Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Kucera2008-01-30 16:48:38 -0500
committerMike Kucera2008-01-30 16:48:38 -0500
commitbf2aafaf4b32cc0405a847bb1958a5af1f1e675f (patch)
treea1aeabba11e17a910a1a67cbe18a768d563a3fc5
parent0aa860ee97029939017674a6ed15269cf277f4f4 (diff)
downloadorg.eclipse.cdt-bf2aafaf4b32cc0405a847bb1958a5af1f1e675f.tar.gz
org.eclipse.cdt-bf2aafaf4b32cc0405a847bb1958a5af1f1e675f.tar.xz
org.eclipse.cdt-bf2aafaf4b32cc0405a847bb1958a5af1f1e675f.zip
created ANT build file to run LPG generator, moved grammar files to separate folder
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml71
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Parser.g (renamed from lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parser.g)59
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/common.g135
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPParser.g (renamed from lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParser.g)10
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99OldParser.g1056
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parser.java17
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99ResolverParser.g1835
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParser.java10
8 files changed, 284 insertions, 2909 deletions
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml b/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml
new file mode 100644
index 0000000000..fe2e4397f7
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml
@@ -0,0 +1,71 @@
+<!--
+ Copyright (c) 2006, 2008 IBM Corporation and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ IBM Corporation - initial API and implementation
+-->
+
+<project name="CDT Extensible LR Parser Framework" default="both" basedir=".">
+ <description>Generates LPG parsers from grammar files</description>
+
+
+ <fail unless="lpg_exe">
+ Property $${lpg_exe} not set.
+ This property must be set to the full path to the LPG generator executable.
+ </fail>
+
+ <fail unless="lpg_template">
+ Property $${lpg_template} not set.
+ This property must be set to the full path to the LPG templates folder.
+ </fail>
+
+
+ <target name="both" depends="cpp, c99">
+ <description>Generates the C99 and C++ parsers</description>
+ <echo message="Done"/>
+ </target>
+
+
+ <target name="cpp">
+ <description>Generate the C++ parser</description>
+ <antcall target="generate">
+ <param name="grammar_dir" value="cpp"/>
+ <param name="grammar_name" value="CPPParser"/>
+ <param name="output_dir" value="org/eclipse/cdt/internal/core/dom/lrparser/cpp"/>
+ </antcall>
+ </target>
+
+ <target name="c99">
+ <description>Generate the C99 parser</description>
+ <antcall target="generate">
+ <param name="grammar_dir" value="c99"/>
+ <param name="grammar_name" value="C99Parser"/>
+ <param name="output_dir" value="org/eclipse/cdt/internal/core/dom/lrparser/c99"/>
+ </antcall>
+ </target>
+
+
+ <target name="generate">
+ <property name="grammar_file" value="${grammar_dir}/${grammar_name}.g"/>
+ <echo message="lpg_exe=${lpg_exe}"/>
+ <echo message="lpg_template=${lpg_template}"/>
+ <echo message="grammar_file=${grammar_file}.g"/>
+ <echo message="output_dir=${output_dir}"/>
+
+ <exec executable="${lpg_exe}">
+ <arg value="${grammar_file}"/>
+ <env key="LPG_TEMPLATE" path="${lpg_template}"/>
+ </exec>
+
+ <move overwrite="true" toDir="../src/${output_dir}">
+ <fileset dir=".">
+ <include name="${grammar_name}*.*"/>
+ </fileset>
+ </move>
+ </target>
+
+</project> \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Parser.g
index 9b6f53fd90..e313c24b6e 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Parser.g
@@ -13,6 +13,9 @@
%options package=org.eclipse.cdt.internal.core.dom.lrparser.c99
%options template=TrialUndoParserTemplate.g
+--$Include
+--../common.g
+--$End
$Notice
-- Copied into all files generated by LPG
@@ -31,8 +34,6 @@ $Notice
./
$End
-
-
$Terminals
-- Keywords
@@ -130,20 +131,37 @@ $Globals
./
$End
+-- TODO move this code into a common template
+
$Define
- -- These macros allow the template and header code to be customized by an extending parser.
- $ast_class /.Object./
- $additional_interfaces /. ./
-
$build_action_class /. C99BuildASTParserAction ./
$resolve_action_class /. C99TypedefTrackerParserAction ./
$node_factory_create_expression /. C99ASTNodeFactory.DEFAULT_INSTANCE ./
-
-
+ $sym_class /. C99Parsersym ./
$lexer_class /. C99Lexer ./
$action_class /. C99ParserAction ./
+$End
+
+
+
+
+$Define
+ -- These macros allow the template and header code to be customized by an extending parser.
+ $ast_class /.Object./
$data_class /. Object ./ -- allow anything to be passed between actions
+ --$additional_interfaces /. , IParserActionTokenProvider, IParser ./
+ $additional_interfaces /. ./
+
+ --$build_action_class /. ./
+ --$resolve_action_class /. ./
+ --$node_factory_create_expression /. ./
+
+
+ --$lexer_class /. ./
+ --$action_class /. ./
+
+
$UndoResolver /.$Undo action.resolver.undo(); $EndUndo./
$Resolve /. $BeginTrial $resolve.
@@ -162,6 +180,15 @@ $Define
$resolve /. action.resolver./
$builder /. action.builder./
+
+-- comment out when using trial/undo
+ --$Action /. $BeginAction ./
+ --$BeginFinal /. ./
+ --$EndFinal /. ./
+ --$BeginTrial /. ./
+ --$EndTrial /. ./
+ --$Undo /. ./
+ --$EndUndo /. ./
$End
@@ -169,12 +196,15 @@ $Headers
/.
private $action_class action;
+ //public $action_type() { // constructor
+ //}
+
private void initActions(IASTTranslationUnit tu) {
// binding resolution actions need access to IASTName nodes, temporary
action = new $action_class();
action.resolver = new $resolve_action_class(this);
action.builder = new $build_action_class($node_factory_create_expression, this, tu);
- action.builder.setTokenMap(C99Parsersym.orderedTerminalSymbols);
+ action.builder.setTokenMap($sym_class.orderedTerminalSymbols);
setParserAction(action);
}
@@ -184,6 +214,12 @@ $Headers
super.addToken(token);
}
+ public void setTokens(List<IToken> tokens) {
+ resetTokenStream();
+ for(IToken token : tokens) {
+ addToken(token);
+ }
+ }
public IASTCompletionNode parse(IASTTranslationUnit tu) {
// this has to be done, or... kaboom!
@@ -206,8 +242,8 @@ $Headers
public int getKind(int i) {
int kind = super.getKind(i);
// lexer feedback hack!
- if(kind == C99Parsersym.TK_identifier && action.resolver.isTypedef(getTokenText(i))) {
- kind = C99Parsersym.TK_TypedefName;
+ if(kind == $sym_class.TK_identifier && action.resolver.isTypedef(getTokenText(i))) {
+ kind = $sym_class.TK_TypedefName;
}
return kind;
}
@@ -215,7 +251,6 @@ $Headers
./
$End
-
$Start
translation_unit
$End
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/common.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/common.g
new file mode 100644
index 0000000000..481c93ff24
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/common.g
@@ -0,0 +1,135 @@
+-----------------------------------------------------------------------------------
+-- Copyright (c) 2006, 2008 IBM Corporation and others.
+-- All rights reserved. This program and the accompanying materials
+-- are made available under the terms of the Eclipse Public License v1.0
+-- which accompanies this distribution, and is available at
+-- http://www.eclipse.org/legal/epl-v10.html
+--
+-- Contributors:
+-- IBM Corporation - initial API and implementation
+-----------------------------------------------------------------------------------
+
+
+$Notice
+-- Copied into all files generated by LPG
+/./*******************************************************************************
+ * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *********************************************************************************/
+
+ // This file was generated by LPG
+./
+$End
+
+
+$Define
+ -- These macros allow the template and header code to be customized by an extending parser.
+ $ast_class /.Object./
+ $data_class /. Object ./ -- allow anything to be passed between actions
+
+ --$additional_interfaces /. , IParserActionTokenProvider, IParser ./
+ $additional_interfaces /. ./
+
+ $build_action_class /. ./
+ $resolve_action_class /. ./
+ $node_factory_create_expression /. ./
+
+
+ $lexer_class /. ./
+ $action_class /. ./
+
+
+ $UndoResolver /.$Undo action.resolver.undo(); $EndUndo./
+
+ $Resolve /. $BeginTrial $resolve.
+ ./
+ $EndResolve /. $EndTrial
+ $UndoResolver
+ ./ -- undo actions are automatically generated for binding resolution actions
+
+ $Builder /. $BeginFinal $builder.
+ ./
+ $EndBuilder /. /*$builder.getASTStack().print();*/ $EndFinal ./
+
+ $Build /. $Action $Builder ./
+ $EndBuild /. $EndBuilder $EndAction ./
+
+ $resolve /. action.resolver./
+ $builder /. action.builder./
+
+
+-- comment out when using trial/undo
+ --$Action /. $BeginAction ./
+ --$BeginFinal /. ./
+ --$EndFinal /. ./
+ --$BeginTrial /. ./
+ --$EndTrial /. ./
+ --$Undo /. ./
+ --$EndUndo /. ./
+$End
+
+
+$Headers
+/.
+ private $action_class action;
+
+ //public $action_type() { // constructor
+ //}
+
+ private void initActions(IASTTranslationUnit tu) {
+ // binding resolution actions need access to IASTName nodes, temporary
+ action = new $action_class();
+ action.resolver = new $resolve_action_class(this);
+ action.builder = new $build_action_class($node_factory_create_expression, this, tu);
+ action.builder.setTokenMap($sym_class.orderedTerminalSymbols);
+ //setParserAction(action);
+ }
+
+
+ public void addToken(IToken token) {
+ token.setKind(mapKind(token.getKind()));
+ super.addToken(token);
+ }
+
+ public void setTokens(List<IToken> tokens) {
+ resetTokenStream();
+ for(IToken token : tokens) {
+ addToken(token);
+ }
+ }
+
+ public IASTCompletionNode parse(IASTTranslationUnit tu) {
+ // this has to be done, or... kaboom!
+ setStreamLength(getSize());
+ initActions(tu);
+
+ final int errorRepairCount = -1; // -1 means full error handling
+ parser(null, errorRepairCount); // do the actual parse
+ super.resetTokenStream(); // allow tokens to be garbage collected
+
+ // the completion node may be null
+ IASTCompletionNode compNode = action.builder.getASTCompletionNode();
+
+ action = null;
+ parserAction = null;
+ return compNode;
+ }
+
+
+ public int getKind(int i) {
+ int kind = super.getKind(i);
+ // lexer feedback hack!
+ //if(kind == $sym_class.TK_identifier && action.resolver.isTypedef(getTokenText(i))) {
+ // kind = $sym_class.TK_TypedefName;
+ //}
+ return kind;
+ }
+
+./
+$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPParser.g
index cb5f582722..ae71784799 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPParser.g
@@ -188,7 +188,8 @@ $Headers
private $action_class action;
// uncomment to use with backtracking parser
- public CPPParser() {}
+ public $action_type() { // constructor
+ }
private void initActions(IASTTranslationUnit tu) {
// binding resolution actions need access to IASTName nodes, temporary
@@ -208,6 +209,13 @@ $Headers
}
+ public void setTokens(List<IToken> tokens) {
+ resetTokenStream();
+ for(IToken token : tokens) {
+ addToken(token);
+ }
+ }
+
public IASTCompletionNode parse(IASTTranslationUnit tu) {
// this has to be done, or... kaboom!
setStreamLength(getSize());
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99OldParser.g b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99OldParser.g
deleted file mode 100644
index 855397df32..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99OldParser.g
+++ /dev/null
@@ -1,1056 +0,0 @@
------------------------------------------------------------------------------------
--- Copyright (c) 2006, 2007 IBM Corporation and others.
--- All rights reserved. This program and the accompanying materials
--- are made available under the terms of the Eclipse Public License v1.0
--- which accompanies this distribution, and is available at
--- http://www.eclipse.org/legal/epl-v10.html
---
--- Contributors:
--- IBM Corporation - initial API and implementation
------------------------------------------------------------------------------------
-
-%options la=2
-%options package=org.eclipse.cdt.internal.core.dom.parser.c99
-%options template=btParserTemplateD.g
-%options import_terminals=C99Lexer.g
-
------------------------------------------------------------------------------------
---
--- This is the old parser from before the trial/undo parsing strategy was
--- adopted.
---
--- This parser is deprecated.
---
------------------------------------------------------------------------------------
-
-$Notice
-/./*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *********************************************************************************/
-
- // This file was generated by LPG
-./
-$End
-
-$Terminals
-
- -- Most terminals are defined in the lexer and imported from there.
- -- This section lists terminals that are not defined in the lexer such as keywords.
-
-
- -- The scanner does not recognize keywords, it will return them as identifier tokens.
- -- An IKeywordMap is used to convert these identifiers to keyword tokens.
-
- auto break case char
- const continue default do
- double else enum extern
- float for goto if
- inline int long register
- restrict return short signed
- sizeof static struct switch
- typedef union unsigned void
- volatile while
- _Bool _Complex _Imaginary
-
-
- -- These are aliases for lexer tokens.
-
-
- LeftBracket ::= '['
- LeftParen ::= '('
- LeftBrace ::= '{'
- Dot ::= '.'
- Arrow ::= '->'
- PlusPlus ::= '++'
- MinusMinus ::= '--'
- And ::= '&'
- Star ::= '*'
- Plus ::= '+'
- Minus ::= '-'
- Tilde ::= '~'
- Bang ::= '!'
- Slash ::= '/'
- Percent ::= '%'
- RightShift ::= '>>'
- LeftShift ::= '<<'
- LT ::= '<'
- GT ::= '>'
- LE ::= '<='
- GE ::= '>='
- EQ ::= '=='
- NE ::= '!='
- Caret ::= '^'
- Or ::= '|'
- AndAnd ::= '&&'
- OrOr ::= '||'
- Question ::= '?'
- Colon ::= ':'
- DotDotDot ::= '...'
- Assign ::= '='
- StarAssign ::= '*='
- SlashAssign ::= '/='
- PercentAssign ::= '%='
- PlusAssign ::= '+='
- MinusAssign ::= '-='
- RightShiftAssign ::= '>>='
- LeftShiftAssign ::= '<<='
- AndAssign ::= '&='
- CaretAssign ::= '^='
- OrAssign ::= '|='
- Comma ::= ','
- Hash ::= '#'
- HashHash ::= '##'
- NewLine ::= 'nl'
-
-
-$End
-
-
-$Globals
-/.
- import java.util.*;
-
- import org.eclipse.cdt.core.dom.ast.*;
- import org.eclipse.cdt.core.dom.c99.IParserActionTokenProvider;
- import org.eclipse.cdt.core.dom.c99.IParser;
- import org.eclipse.cdt.core.dom.c99.IParseResult;
- import org.eclipse.cdt.core.dom.parser.c99.C99ParseResult;
- import org.eclipse.cdt.core.dom.parser.c99.C99ParserAction;
- import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
- import org.eclipse.cdt.core.dom.c99.IKeywordMap;
- import org.eclipse.cdt.core.dom.parser.c99.C99KeywordMap;
- import org.eclipse.cdt.core.dom.c99.IPreprocessorTokenCollector;
-./
-$End
-
-$Define
-
- -- These macros allow the header code to be customized by an extending parser.
-
- $ast_class /.Object./
- $ba /.$BeginAction action.beforeConsume(); action. ./
- $ea /.$EndAction./
- $additional_interfaces /. , IParserActionTokenProvider, IParser, IPreprocessorTokenCollector<IToken> ./
-
- $action_class /. C99ParserAction ./
- $keyword_map_class /. C99KeywordMap ./
- $lexer_class /. C99Lexer ./
-$End
-
-
-$Headers
-/.
- private $action_class action = new $action_class(this);
- private List commentTokens = new ArrayList();
- private IKeywordMap keywordMap = new $keyword_map_class();
-
- public $action_type() { // constructor
- this(new $lexer_class());
- }
-
- public void addToken(IToken token) {
- int newKind = mapKind(token.getKind());
- if(newKind == $prs_type.TK_identifier) {
- Integer keywordKind = keywordMap.getKeywordKind(token.toString());
- if(keywordKind != null) {
- newKind = keywordKind.intValue();
- }
- }
- token.setKind(newKind);
- super.addToken(token);
- }
-
- public void addCommentToken(IToken token) {
- commentTokens.add(token);
- }
-
- public List getCommentTokens() {
- return commentTokens;
- }
-
- public void resetTokenStream() {
- super.resetTokenStream();
- action = new $action_class(this);
- commentTokens = new ArrayList();
- }
-
-
- public IParseResult parse() {
- // this has to be done, or... kaboom!
- setStreamLength(getSize());
-
- final int errorRepairCount = -1; // -1 means full error handling
-
- if(btParser == null) {
- parser(null, errorRepairCount);
- }
- else {
- try
- {
- // reuse the same btParser object for speed
- // (creating an new instance for every translation unit is dirt slow)
- btParser.parse(errorRepairCount);
- }
- catch (BadParseException e)
- {
- reset(e.error_token); // point to error token
- DiagnoseParser diagnoseParser = new DiagnoseParser(this, prs);
- diagnoseParser.diagnose(e.error_token);
- }
- }
-
- IASTTranslationUnit tu = action.getAST();
- boolean encounteredError = action.encounteredError();
- IASTCompletionNode compNode = action.getASTCompletionNode();
-
- resetTokenStream(); // important, allows memory to be reclaimed
- return new C99ParseResult(tu, compNode, encounteredError);
- }
-
-
- // implements IParserActionTokenProvider.getEOFToken()
- public IToken getEOFToken() {
- List tokens = getTokens();
- IToken eof = (IToken) tokens.get(tokens.size() - 1);
- return eof;
- }
-
-
- // implements IParserActionTokenProvider.getRuleTokenCount()
- public int getRuleTokenCount() {
- return (getRightSpan() - getLeftSpan()) + 1;
- }
-
- public List getRuleTokens() {
- return Collections.unmodifiableList(getTokens().subList(getLeftSpan(), getRightSpan() + 1));
- }
-
-./
-$End
-
-
-$Start -- the start symbol
- translation_unit
-$End
-
-
-
-$Rules
-
--------------------------------------------------------------------------------------------
--- AST Scoping
---
--- Special empty rule used to trigger the opening of a new AST scope
--------------------------------------------------------------------------------------------
-
-
-<openscope> ::= $empty /.$ba openASTScope(); $ea./
-
-
--------------------------------------------------------------------------------------------
--- Content assist
--------------------------------------------------------------------------------------------
-
-
-identifier_or_completion
- ::= 'identifier'
- | 'Completion'
-
-']' ::=? 'RightBracket'
- | 'EndOfCompletion'
-
-')' ::=? 'RightParen'
- | 'EndOfCompletion'
-
-'}' ::=? 'RightBrace'
- | 'EndOfCompletion'
-
-';' ::=? 'SemiColon'
- | 'EndOfCompletion'
-
-
--------------------------------------------------------------------------------------------
--- Expressions
--------------------------------------------------------------------------------------------
-
-
-constant
- ::= 'integer'
- /.$ba consumeExpressionConstant(IASTLiteralExpression.lk_integer_constant); $ea./
- | 'floating'
- /.$ba consumeExpressionConstant(IASTLiteralExpression.lk_float_constant); $ea./
- | 'charconst'
- /.$ba consumeExpressionConstant(IASTLiteralExpression.lk_char_constant); $ea./
- | 'stringlit'
- /.$ba consumeExpressionConstant(IASTLiteralExpression.lk_string_literal); $ea./
-
-primary_expression
- ::= constant
- | identifier_or_completion
- /.$ba consumeExpressionID(); $ea./
- | '(' expression ')'
- /.$ba consumeExpressionBracketed(); $ea./
-
-postfix_expression
- ::= primary_expression
- | postfix_expression '[' expression ']'
- /.$ba consumeExpressionArraySubscript(); $ea./
- | postfix_expression '(' ')'
- /.$ba consumeExpressionFunctionCall(false); $ea./
- | postfix_expression '(' argument_expression_list ')'
- /.$ba consumeExpressionFunctionCall(true); $ea./
- | postfix_expression '.' member_name
- /.$ba consumeExpressionFieldReference(false); $ea./
- | postfix_expression '->' member_name
- /.$ba consumeExpressionFieldReference(true); $ea./
- | postfix_expression '++'
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_postFixIncr); $ea./
- | postfix_expression '--'
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_postFixDecr); $ea./
- | '(' type_name ')' '{' <openscope> initializer_list '}'
- /.$ba consumeExpressionTypeIdInitializer(); $ea./
- | '(' type_name ')' '{' <openscope> initializer_list ',' '}'
- /.$ba consumeExpressionTypeIdInitializer(); $ea./
-
-
-member_name
- ::= identifier_or_completion
-
-
-argument_expression_list
- ::= assignment_expression
- /.$ba consumeExpressionList(true); $ea./
- | argument_expression_list ',' assignment_expression
- /.$ba consumeExpressionList(false); $ea./
-
-unary_expression
- ::= postfix_expression
- | '++' unary_expression
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_prefixIncr); $ea./
- | '--' unary_expression
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_prefixDecr); $ea./
- | '&' cast_expression
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_amper); $ea./
- | '*' cast_expression
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_star); $ea./
- | '+' cast_expression
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_plus); $ea./
- | '-' cast_expression
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_minus); $ea./
- | '~' cast_expression
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_tilde); $ea./
- | '!' cast_expression
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_not); $ea./
- | 'sizeof' unary_expression
- /.$ba consumeExpressionUnaryOperator(IASTUnaryExpression.op_sizeof); $ea./
- | 'sizeof' '(' type_name ')'
- /.$ba consumeExpressionUnarySizeofTypeName(); $ea./
-
- -- ambiguity here because type_name can be an identifier and unary_expression can be an identifier in brackets
- -- TODO: will need a way of disambiguation, (parse both ways)
-
-cast_expression
- ::= unary_expression
- | '(' type_name ')' cast_expression
- /.$ba consumeExpressionCast(); $ea./
-
-
-multiplicative_expression
- ::= cast_expression
- | multiplicative_expression '*' cast_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_multiply); $ea./
- | multiplicative_expression '/' cast_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_divide); $ea./
- | multiplicative_expression '%' cast_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_modulo); $ea./
-
-additive_expression
- ::= multiplicative_expression
- | additive_expression '+' multiplicative_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_plus); $ea./
- | additive_expression '-' multiplicative_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_minus); $ea./
-
-shift_expression
- ::= additive_expression
- | shift_expression '<<' additive_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftLeft); $ea./
- | shift_expression '>>' additive_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftRight); $ea./
-
-relational_expression
- ::= shift_expression
- | relational_expression '<' shift_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_lessThan); $ea./
- | relational_expression '>' shift_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_greaterThan); $ea./
- | relational_expression '<=' shift_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_lessEqual); $ea./
- | relational_expression '>=' shift_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_greaterEqual); $ea./
-
-equality_expression
- ::= relational_expression
- | equality_expression '==' relational_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_equals); $ea./
- | equality_expression '!=' relational_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_notequals); $ea./
-
-AND_expression
- ::= equality_expression
- | AND_expression '&' equality_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryAnd); $ea./
-
-exclusive_OR_expression
- ::= AND_expression
- | exclusive_OR_expression '^' AND_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryXor); $ea./
-
-inclusive_OR_expression
- ::= exclusive_OR_expression
- | inclusive_OR_expression '|' exclusive_OR_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryOr); $ea./
-
-logical_AND_expression
- ::= inclusive_OR_expression
- | logical_AND_expression '&&' inclusive_OR_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_logicalAnd); $ea./
-
-logical_OR_expression
- ::= logical_AND_expression
- | logical_OR_expression '||' logical_AND_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_logicalOr); $ea./
-
-conditional_expression
- ::= logical_OR_expression
- | logical_OR_expression '?' expression ':' conditional_expression
- /.$ba consumeExpressionConditional(); $ea./
-
-assignment_expression
- ::= conditional_expression
- | unary_expression '=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_assign); $ea./
- | unary_expression '*=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_multiplyAssign); $ea./
- | unary_expression '/=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_divideAssign); $ea./
- | unary_expression '%=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_moduloAssign); $ea./
- | unary_expression '+=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_plusAssign); $ea./
- | unary_expression '-=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_minusAssign); $ea./
- | unary_expression '<<=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftLeftAssign); $ea./
- | unary_expression '>>=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftRightAssign); $ea./
- | unary_expression '&=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryAndAssign); $ea./
- | unary_expression '^=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryXorAssign); $ea./
- | unary_expression '|=' assignment_expression
- /.$ba consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryOrAssign); $ea./
-
-
--- special rule to avoid confict between problem statments and problem expressions
-expression_in_statement
- ::= expression_list
- /.$ba consumeExpression(); $ea./
-
-expression
- ::= expression_list
- /.$ba consumeExpression(); $ea./
- --| ERROR_TOKEN
- -- /.$ba consumeExpressionProblem(); $ea./
-
-expression_list
- ::= assignment_expression
- /.$ba consumeExpressionList(true); $ea./
- | expression_list ',' assignment_expression
- /.$ba consumeExpressionList(false); $ea./
-
-constant_expression
- ::= conditional_expression
- --| ERROR_TOKEN
- -- /.$ba consumeExpressionProblem(); $ea./
- -- I think expressions will have to go at the bottom of the grammar for this to work
-
-
--------------------------------------------------------------------------------------------
--- Statements
--------------------------------------------------------------------------------------------
-
-statement
- ::= labeled_statement
- | compound_statement
- | expression_statement
- | selection_statement
- | iteration_statement
- | jump_statement
- | ERROR_TOKEN
- /.$ba consumeStatementProblem(); $ea./
-
-
-labeled_statement
- ::= label_identifier ':' statement
- /.$ba consumeStatementLabeled(); $ea./
- | 'case' constant_expression ':'
- /.$ba consumeStatementCase(); $ea./
- | 'default' ':'
- /.$ba consumeStatementDefault(); $ea./
-
-
-label_identifier
- ::= 'identifier'
- /.$ba consumeName(); $ea./
-
-
-compound_statement
- ::= '{' '}'
- /.$ba consumeStatementEmptyCompoundStatement(); $ea./
- | '{' <openscope> block_item_list '}'
- /.$ba consumeStatementCompoundStatement(); $ea./
-
-
-block_item_list
- ::= block_item
- | block_item_list block_item
-
-
-block_item
- ::= statement
- | declaration
- /.$ba consumeStatementDeclaration(); $ea./
-
-
-expression_statement
- ::= ';'
- /.$ba consumeStatementNull(); $ea./
- | expression_in_statement ';'
- /.$ba consumeStatementExpression(); $ea./
-
-
-selection_statement
- ::= 'if' '(' expression ')' statement
- /.$ba consumeStatementIfThen(); $ea./
- | 'if' '(' expression ')' statement 'else' statement
- /.$ba consumeStatementIfThenElse(); $ea./
- | 'switch' '(' expression ')' statement
- /.$ba consumeStatementSwitch(); $ea./
-
-
-iteration_statement
- ::= 'do' statement 'while' '(' expression ')' ';'
- /.$ba consumeStatementDoLoop(); $ea./
- | 'while' '(' expression ')' statement
- /.$ba consumeStatementWhileLoop(); $ea./
- | 'for' '(' expression ';' expression ';' expression ')' statement
- /.$ba consumeStatementForLoop(true, true, true); $ea./
- | 'for' '(' expression ';' expression ';' ')' statement
- /.$ba consumeStatementForLoop(true, true, false); $ea./
- | 'for' '(' expression ';' ';' expression ')' statement
- /.$ba consumeStatementForLoop(true, false, true); $ea./
- | 'for' '(' expression ';' ';' ')' statement
- /.$ba consumeStatementForLoop(true, false, false); $ea./
- | 'for' '(' ';' expression ';' expression ')' statement
- /.$ba consumeStatementForLoop(false, true, true); $ea./
- | 'for' '(' ';' expression ';' ')' statement
- /.$ba consumeStatementForLoop(false, true, false); $ea./
- | 'for' '(' ';' ';' expression ')' statement
- /.$ba consumeStatementForLoop(false, false, true); $ea./
- | 'for' '(' ';' ';' ')' statement
- /.$ba consumeStatementForLoop(false, false, false); $ea./
- | 'for' '(' declaration expression ';' expression ')' statement
- /.$ba consumeStatementForLoop(true, true, true); $ea./
- | 'for' '(' declaration expression ';' ')' statement
- /.$ba consumeStatementForLoop(true, true, false); $ea./
- | 'for' '(' declaration ';' expression ')' statement
- /.$ba consumeStatementForLoop(true, false, true); $ea./
- | 'for' '(' declaration ';' ')' statement
- /.$ba consumeStatementForLoop(true, false, false); $ea./
-
-
-jump_statement
- ::= 'goto' goto_identifier ';'
- /.$ba consumeStatementGoto(); $ea./
- | 'continue' ';'
- /.$ba consumeStatementContinue(); $ea./
- | 'break' ';'
- /.$ba consumeStatementBreak(); $ea./
- | 'return' ';'
- /.$ba consumeStatementReturn(false); $ea./
- | 'return' expression ';'
- /.$ba consumeStatementReturn(true); $ea./
-
-
-goto_identifier
- ::= 'identifier'
- /.$ba consumeName(); $ea./
-
-
--------------------------------------------------------------------------------------------
--- Declarations
--------------------------------------------------------------------------------------------
-
-declaration
- ::= declaration_specifiers ';'
- /.$ba consumeDeclaration(false); $ea./
- | declaration_specifiers <openscope> init_declarator_list ';'
- /.$ba consumeDeclaration(true); $ea./
-
-
-declaration_specifiers
- ::= <openscope> simple_declaration_specifiers
- /.$ba consumeDeclarationSpecifiersSimple(); $ea./
- | <openscope> struct_or_union_declaration_specifiers
- /.$ba consumeDeclarationSpecifiersStructUnionEnum(); $ea./
- | <openscope> enum_declaration_specifiers
- /.$ba consumeDeclarationSpecifiersStructUnionEnum(); $ea./
- | <openscope> typdef_name_declaration_specifiers
- /.$ba consumeDeclarationSpecifiersTypedefName(); $ea./
-
-
-no_type_declaration_specifier
- ::= storage_class_specifier
- | type_qualifier
- | function_specifier
-
-
-no_type_declaration_specifiers
- ::= no_type_declaration_specifier
- | no_type_declaration_specifiers no_type_declaration_specifier
-
-
-simple_declaration_specifiers
- ::= type_specifier
- | no_type_declaration_specifiers type_specifier
- | simple_declaration_specifiers type_specifier
- | simple_declaration_specifiers no_type_declaration_specifier
-
-
-struct_or_union_declaration_specifiers
- ::= struct_or_union_specifier
- | no_type_declaration_specifiers struct_or_union_specifier
- | struct_or_union_declaration_specifiers no_type_declaration_specifier
-
-
-enum_declaration_specifiers
- ::= enum_specifier
- | no_type_declaration_specifiers enum_specifier
- | enum_declaration_specifiers no_type_declaration_specifier
-
-
-typdef_name_declaration_specifiers
- ::= typedef_name
- | no_type_declaration_specifiers typedef_name
- | typdef_name_declaration_specifiers no_type_declaration_specifier
-
-
-init_declarator_list
- ::= init_declarator
- | init_declarator_list ',' init_declarator
-
-init_declarator
- ::= declarator
- | declarator '=' initializer
- /.$ba consumeDeclaratorWithInitializer(); $ea./
-
-
--- at most one storage_class_specifier is allowed in the declaration specifiers
-storage_class_specifier
- ::= 'typedef' /.$ba consumeToken(); $ea./
- | 'extern' /.$ba consumeToken(); $ea./
- | 'static' /.$ba consumeToken(); $ea./
- | 'auto' /.$ba consumeToken(); $ea./
- | 'register' /.$ba consumeToken(); $ea./
-
-
-type_specifier
- ::= 'void' /.$ba consumeToken(); $ea./
- | 'char' /.$ba consumeToken(); $ea./
- | 'short' /.$ba consumeToken(); $ea./
- | 'int' /.$ba consumeToken(); $ea./
- | 'long' /.$ba consumeToken(); $ea./
- | 'float' /.$ba consumeToken(); $ea./
- | 'double' /.$ba consumeToken(); $ea./
- | 'signed' /.$ba consumeToken(); $ea./
- | 'unsigned' /.$ba consumeToken(); $ea./
- | '_Bool' /.$ba consumeToken(); $ea./
- | '_Complex' /.$ba consumeToken(); $ea./
- | '_Imaginary' /.$ba consumeToken(); $ea./
-
-
-
-typedef_name
- ::= identifier_or_completion /.$ba consumeToken(); $ea./
-
-
-struct_or_union_specifier
- ::= 'struct' '{' <openscope> struct_declaration_list_opt '}'
- /.$ba consumeTypeSpecifierComposite(false, IASTCompositeTypeSpecifier.k_struct); $ea./
-
- | 'union' '{' <openscope> struct_declaration_list_opt '}'
- /.$ba consumeTypeSpecifierComposite(false, IASTCompositeTypeSpecifier.k_union); $ea./
-
- | 'struct' struct_or_union_identifier '{' <openscope> struct_declaration_list_opt '}'
- /.$ba consumeTypeSpecifierComposite(true, IASTCompositeTypeSpecifier.k_struct); $ea./
-
- | 'union' struct_or_union_identifier '{' <openscope> struct_declaration_list_opt '}'
- /.$ba consumeTypeSpecifierComposite(true, IASTCompositeTypeSpecifier.k_union); $ea./
-
- | 'struct' struct_or_union_identifier
- /.$ba consumeTypeSpecifierElaborated(IASTElaboratedTypeSpecifier.k_struct); $ea./
-
- | 'union' struct_or_union_identifier
- /.$ba consumeTypeSpecifierElaborated(IASTElaboratedTypeSpecifier.k_union); $ea./
-
-
-struct_or_union_identifier
- ::= 'identifier'
- /.$ba consumeName(); $ea./
-
-struct_declaration_list_opt
- ::= struct_declaration_list
- | $empty
-
-struct_declaration_list
- ::= struct_declaration
- | struct_declaration_list struct_declaration
-
-
-struct_declaration
- ::= specifier_qualifier_list <openscope> struct_declarator_list ';' -- regular declarators plus bit fields
- /.$ba consumeStructDeclaration(true); $ea./ -- TODO is it okay to reuse consumeDeclaration() ?
- | specifier_qualifier_list ';'
- /.$ba consumeStructDeclaration(false); $ea./
-
-
--- just reuse declaration_specifiers, makes grammar a bit more lenient but thats ok
-specifier_qualifier_list
- ::= declaration_specifiers
-
-
-struct_declarator_list
- ::= struct_declarator
- | struct_declarator_list ',' struct_declarator
-
-struct_declarator
- ::= declarator
- | ':' constant_expression
- /.$ba consumeStructBitField(false); $ea./
- | declarator ':' constant_expression
- /.$ba consumeStructBitField(true); $ea./
-
-
-enum_identifier
- ::= 'identifier' /.$ba consumeName(); $ea./
-
-
-enum_specifier
- ::= 'enum' '{' <openscope> enumerator_list_opt '}'
- /.$ba consumeTypeSpecifierEnumeration(false); $ea./
-
- | 'enum' enum_identifier '{' <openscope> enumerator_list_opt '}'
- /.$ba consumeTypeSpecifierEnumeration(true); $ea./
-
- | 'enum' '{' <openscope> enumerator_list_opt ',' '}'
- /.$ba consumeTypeSpecifierEnumeration(false); $ea./
-
- | 'enum' enum_identifier '{' <openscope> enumerator_list_opt ',' '}'
- /.$ba consumeTypeSpecifierEnumeration(true); $ea./
-
- | 'enum' enum_identifier
- /.$ba consumeTypeSpecifierElaborated(IASTElaboratedTypeSpecifier.k_enum); $ea./
-
-
-enumerator_list_opt
- ::= enumerator_list
- | $empty
-
-enumerator_list
- ::= enumerator
- | enumerator_list ',' enumerator
-
-
-enumerator
- ::= enum_identifier
- /.$ba consumeEnumerator(false); $ea./
- | enum_identifier '=' constant_expression
- /.$ba consumeEnumerator(true); $ea./
-
-
-type_qualifier
- ::= 'const' /.$ba consumeToken(); $ea./
- | 'restrict' /.$ba consumeToken(); $ea./
- | 'volatile' /.$ba consumeToken(); $ea./
-
-function_specifier
- ::= 'inline' /.$ba consumeToken(); $ea./
-
-
-declarator
- ::= direct_declarator
- | <openscope> pointer direct_declarator
- /.$ba consumeDeclaratorWithPointer(true); $ea./
-
-
-direct_declarator
- ::= 'identifier'
- /.$ba consumeDirectDeclaratorIdentifier(); $ea./
-
- | '(' declarator ')'
- /.$ba consumeDirectDeclaratorBracketed(); $ea./
-
- | array_direct_declarator
-
- | function_direct_declarator
-
-
-
-array_direct_declarator
- ::= direct_declarator array_modifier
- /.$ba consumeDirectDeclaratorArrayDeclarator(); $ea./
-
-
-
-function_direct_declarator
- ::= direct_declarator '(' <openscope> parameter_type_list ')'
- /.$ba consumeDirectDeclaratorFunctionDeclarator(true); $ea./
-
- | direct_declarator '(' ')'
- /.$ba consumeDirectDeclaratorFunctionDeclarator(false); $ea./
-
-
-function_declarator
- ::= function_direct_declarator
- | <openscope> pointer function_direct_declarator
- /.$ba consumeDeclaratorWithPointer(true); $ea./
-
-
--- This is a hack because the parser cannot tell the difference between
--- plain identifiers and types. Because of this an identifier_list would
--- always be parsed as a parameter_type_list instead. In a KnR funciton
--- definition we can use the extra list of declarators to disambiguate.
--- This rule should be merged back into direct_declarator if type info is
--- added to the parser.
-knr_direct_declarator
- ::= direct_declarator '(' <openscope> identifier_list ')'
- /.$ba consumeDirectDeclaratorFunctionDeclaratorKnR(); $ea./
-
-
-knr_function_declarator
- ::= knr_direct_declarator
- | <openscope> pointer knr_direct_declarator
- /.$ba consumeDeclaratorWithPointer(true); $ea./
-
-
-array_modifier
- ::= '[' ']'
- /.$ba consumeDirectDeclaratorArrayModifier(false); $ea./
-
- | '[' <openscope> type_qualifier_list ']'
- /.$ba consumeDirectDeclaratorModifiedArrayModifier(false, false, true, false); $ea./
-
- | '[' assignment_expression ']'
- /.$ba consumeDirectDeclaratorArrayModifier(true ); $ea./
-
- | '[' <openscope> type_qualifier_list assignment_expression ']'
- /.$ba consumeDirectDeclaratorModifiedArrayModifier(false, false, true, true ); $ea./
-
- | '[' 'static' assignment_expression ']'
- /.$ba consumeDirectDeclaratorModifiedArrayModifier(true, false, false, true ); $ea./
-
- | '[' 'static' <openscope> type_qualifier_list assignment_expression ']'
- /.$ba consumeDirectDeclaratorModifiedArrayModifier(true, false, true, true ); $ea./
-
- | '[' <openscope> type_qualifier_list 'static' assignment_expression ']'
- /.$ba consumeDirectDeclaratorModifiedArrayModifier(true, false, true, true ); $ea./
-
- | '[' '*' ']'
- /.$ba consumeDirectDeclaratorModifiedArrayModifier(false, true, false, false); $ea./
-
- | '[' <openscope> type_qualifier_list '*' ']'
- /.$ba consumeDirectDeclaratorModifiedArrayModifier(false, true, true, false); $ea./
-
-
-pointer
- ::= '*'
- /.$ba consumePointer(); $ea./
- | pointer '*'
- /.$ba consumePointer(); $ea./
- | '*' <openscope> type_qualifier_list
- /.$ba consumePointerTypeQualifierList(); $ea./
- | pointer '*' <openscope> type_qualifier_list
- /.$ba consumePointerTypeQualifierList(); $ea./
-
-type_qualifier_list
- ::= type_qualifier
- | type_qualifier_list type_qualifier
-
-parameter_type_list
- ::= parameter_list
- | parameter_list ',' '...'
- | '...' -- not spec
-
-parameter_list
- ::= parameter_declaration
- | parameter_list ',' parameter_declaration
-
-parameter_declaration
- ::= declaration_specifiers init_declarator
- /.$ba consumeParameterDeclaration(true); $ea./
- | declaration_specifiers
- /.$ba consumeParameterDeclaration(false); $ea./
- | declaration_specifiers abstract_declarator
- /.$ba consumeParameterDeclaration(true); $ea./
-
-
-identifier_list
- ::= 'identifier'
- /.$ba consumeName(); $ea./
- | identifier_list ',' 'identifier'
- /.$ba consumeName(); $ea./
-
-type_name
- ::= specifier_qualifier_list
- /.$ba consumeTypeId(false); $ea./
- | specifier_qualifier_list abstract_declarator
- /.$ba consumeTypeId(true); $ea./
-
-
-abstract_declarator -- a declarator that does not include an identifier
- ::= <openscope> pointer
- /.$ba consumeDeclaratorWithPointer(false); $ea./
- | direct_abstract_declarator
- | <openscope> pointer direct_abstract_declarator
- /.$ba consumeDeclaratorWithPointer(true); $ea./
-
-
--- rewritten to use the more general array_modifier rule
-direct_abstract_declarator
- ::= '(' abstract_declarator ')'
- /.$ba consumeDirectDeclaratorBracketed(); $ea./
-
- | array_modifier
- /.$ba consumeAbstractDeclaratorArrayModifier(false); $ea./
-
- | direct_abstract_declarator array_modifier
- /.$ba consumeAbstractDeclaratorArrayModifier(true); $ea./
-
- | '(' ')'
- /.$ba consumeAbstractDeclaratorFunctionDeclarator(false, false); $ea./
-
- | direct_abstract_declarator '(' ')'
- /.$ba consumeAbstractDeclaratorFunctionDeclarator(true, false); $ea./
-
- | '(' <openscope> parameter_type_list ')'
- /.$ba consumeAbstractDeclaratorFunctionDeclarator(false, true); $ea./
-
- | direct_abstract_declarator '(' <openscope> parameter_type_list ')'
- /.$ba consumeAbstractDeclaratorFunctionDeclarator(true, true); $ea./
-
-
-initializer
- ::= assignment_expression
- /.$ba consumeInitializer(); $ea./
- | '{' <openscope> initializer_list '}'
- /.$ba consumeInitializerList(); $ea./
- | '{' <openscope> initializer_list ',' '}'
- /.$ba consumeInitializerList(); $ea./
-
-
-initializer_list
- ::= initializer
- | designated_initializer
- | initializer_list ',' initializer
- | initializer_list ',' designated_initializer
-
-
-
-designated_initializer
- ::= <openscope> designation initializer
- /.$ba consumeInitializerDesignated(); $ea./
-
-designation
- ::= designator_list '='
-
-designator_list
- ::= designator
- | designator_list designator
-
-designator
- ::= '[' constant_expression ']'
- /.$ba consumeDesignatorArrayDesignator(); $ea./
- | '.' 'identifier'
- /.$ba consumeDesignatorFieldDesignator(); $ea./
-
-
-
-
-
-
-
-
--------------------------------------------------------------------------------------------
--- External Definitions
--------------------------------------------------------------------------------------------
-
-translation_unit
- ::= external_declaration_list
- /.$ba consumeTranslationUnit(); $ea./
- | $empty
- /.$ba consumeTranslationUnit(); $ea./
-
-external_declaration_list
- ::= external_declaration
- | external_declaration_list external_declaration
-
-external_declaration
- ::= function_definition
- | declaration
- | ';'
- /.$ba consumeDeclarationEmpty(); $ea./
- | ERROR_TOKEN
- /.$ba consumeDeclarationProblem(); $ea./
-
--- The extra <openscope> nonterminal before declarator in this rule is only there
--- to avoid a shift/reduce error with the rule for declaration.
-function_definition
- ::= declaration_specifiers <openscope> function_declarator compound_statement
- /.$ba consumeFunctionDefinition(true); $ea./
- | declaration_specifiers <openscope> knr_function_declarator <openscope> declaration_list compound_statement
- /.$ba consumeFunctionDefinitionKnR(); $ea./
-
- -- this rule is here as a special case just to support implicit int in function definitions
- | function_declarator compound_statement
- /.$ba consumeFunctionDefinition(false); $ea./
-
-
-declaration_list
- ::= declaration
- | declaration_list declaration
-
-$End
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parser.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parser.java
index 21fd9657b1..cea3422a98 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parser.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parser.java
@@ -29,7 +29,7 @@ import org.eclipse.cdt.core.dom.lrparser.action.c99.C99BuildASTParserAction;
import org.eclipse.cdt.core.dom.lrparser.action.c99.C99TypedefTrackerParserAction;
import org.eclipse.cdt.core.dom.lrparser.util.DebugUtil;
-public class C99Parser extends AbstractTrialUndoActionProvider< C99ParserAction , Object > implements IParserActionTokenProvider, IParser {
+public class C99Parser extends AbstractTrialUndoActionProvider< C99ParserAction , Object > implements IParserActionTokenProvider, IParser {
private static ParseTable prs = new C99Parserprs();
protected static final Action< C99ParserAction , Object >[] RULE_ACTIONS;
@@ -131,12 +131,15 @@ public class C99Parser extends AbstractTrialUndoActionProvider< C99ParserAction
private C99ParserAction action;
+//public C99Parser() { // constructor
+//}
+
private void initActions(IASTTranslationUnit tu) {
// binding resolution actions need access to IASTName nodes, temporary
action = new C99ParserAction ();
action.resolver = new C99TypedefTrackerParserAction (this);
action.builder = new C99BuildASTParserAction ( C99ASTNodeFactory.DEFAULT_INSTANCE , this, tu);
- action.builder.setTokenMap(C99Parsersym.orderedTerminalSymbols);
+ action.builder.setTokenMap( C99Parsersym .orderedTerminalSymbols);
setParserAction(action);
}
@@ -146,6 +149,12 @@ public void addToken(IToken token) {
super.addToken(token);
}
+public void setTokens(List<IToken> tokens) {
+ resetTokenStream();
+ for(IToken token : tokens) {
+ addToken(token);
+ }
+}
public IASTCompletionNode parse(IASTTranslationUnit tu) {
// this has to be done, or... kaboom!
@@ -168,8 +177,8 @@ public IASTCompletionNode parse(IASTTranslationUnit tu) {
public int getKind(int i) {
int kind = super.getKind(i);
// lexer feedback hack!
- if(kind == C99Parsersym.TK_identifier && action.resolver.isTypedef(getTokenText(i))) {
- kind = C99Parsersym.TK_TypedefName;
+ if(kind == C99Parsersym .TK_identifier && action.resolver.isTypedef(getTokenText(i))) {
+ kind = C99Parsersym .TK_TypedefName;
}
return kind;
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99ResolverParser.g b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99ResolverParser.g
deleted file mode 100644
index 69a6f51352..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99ResolverParser.g
+++ /dev/null
@@ -1,1835 +0,0 @@
------------------------------------------------------------------------------------
--- Copyright (c) 2006, 2007 IBM Corporation and others.
--- All rights reserved. This program and the accompanying materials
--- are made available under the terms of the Eclipse Public License v1.0
--- which accompanies this distribution, and is available at
--- http://www.eclipse.org/legal/epl-v10.html
---
--- Contributors:
--- IBM Corporation - initial API and implementation
------------------------------------------------------------------------------------
-
-%options la=2
-%options package=org.eclipse.cdt.internal.core.dom.lrparser.c99
-%options template=TrialUndoParserTemplate.g
-%options import_terminals=C99Lexer.g
-
------------------------------------------------------------------------------------
---
--- An attempt was made to create a C99 parser that has the ability to do all the
--- binding resolution during the parse. This parser was meant to be used with
--- the C99ResolveParserAction class.
---
--- This initiative has since been abandoned and therefore this parser does
--- not work correctly, use C99Parser.g instead.
---
--- This parser is deprecated.
---
------------------------------------------------------------------------------------
-
-$Notice
-/./*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *********************************************************************************/
-
- // This file was generated by LPG
-./
-$End
-
-$Terminals
-
- -- Most terminals are defined in the lexer and imported from there.
- -- This section lists terminals that are not defined in the lexer such as keywords.
-
-
- -- The scanner does not recognize keywords, it will return them as identifier tokens.
- -- An IKeywordMap is used to convert these identifiers to keyword tokens.
-
- auto break case char
- const continue default do
- double else enum extern
- float for goto if
- inline int long register
- restrict return short signed
- sizeof static struct switch
- typedef union unsigned void
- volatile while
- _Bool _Complex _Imaginary
-
-
- -- Special token used to represent an identifier that has been declared as a typedef name.
- -- This is the lexer feedback hack.
-
- TypedefName
-
-
- -- These are aliases for lexer tokens.
-
-
- LeftBracket ::= '['
- LeftParen ::= '('
- LeftBrace ::= '{'
- Dot ::= '.'
- Arrow ::= '->'
- PlusPlus ::= '++'
- MinusMinus ::= '--'
- And ::= '&'
- Star ::= '*'
- Plus ::= '+'
- Minus ::= '-'
- Tilde ::= '~'
- Bang ::= '!'
- Slash ::= '/'
- Percent ::= '%'
- RightShift ::= '>>'
- LeftShift ::= '<<'
- LT ::= '<'
- GT ::= '>'
- LE ::= '<='
- GE ::= '>='
- EQ ::= '=='
- NE ::= '!='
- Caret ::= '^'
- Or ::= '|'
- AndAnd ::= '&&'
- OrOr ::= '||'
- Question ::= '?'
- Colon ::= ':'
- DotDotDot ::= '...'
- Assign ::= '='
- StarAssign ::= '*='
- SlashAssign ::= '/='
- PercentAssign ::= '%='
- PlusAssign ::= '+='
- MinusAssign ::= '-='
- RightShiftAssign ::= '>>='
- LeftShiftAssign ::= '<<='
- AndAssign ::= '&='
- CaretAssign ::= '^='
- OrAssign ::= '|='
- Comma ::= ','
-
-
-$End
-
-
-$Globals
-/.
- import java.util.*;
-
- import org.eclipse.cdt.core.dom.ast.*;
- import org.eclipse.cdt.core.dom.lrparser.IKeywordMap;
- import org.eclipse.cdt.core.dom.lrparser.IParseResult;
- import org.eclipse.cdt.core.dom.lrparser.IParser;
- import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
- import org.eclipse.cdt.core.dom.lrparser.action.c99.C99BuildASTParserAction;
- import org.eclipse.cdt.core.dom.lrparser.action.c99.C99ResolveParserAction;
- import org.eclipse.cdt.core.dom.lrparser.c99.C99KeywordMap;
- import org.eclipse.cdt.core.dom.lrparser.c99.C99ParseResult;
- import org.eclipse.cdt.core.dom.lrparser.preprocessor.IPreprocessorTokenCollector;
- import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
- import org.eclipse.cdt.core.dom.lrparser.util.DebugUtil;
-./
-$End
-
-$Define
- -- These macros allow the template and header code to be customized by an extending parser.
- $ast_class /.Object./
- $additional_interfaces /. , IPreprocessorTokenCollector<IToken> ./
-
- $build_action_class /. C99BuildASTParserAction ./
- $resolve_action_class /. C99ResolveParserAction ./
-
- $keyword_map_class /. C99KeywordMap ./
- $lexer_class /. C99Lexer ./
- $action_class /. C99ParserAction ./
- $data_class /. Object ./ -- allow anything to be passed between actions
-
- $UndoResolver /.$Undo action.resolver.undo(); $EndUndo./
-
- $Resolve /. $BeginTrial
- ./
- $EndResolve /. $EndTrial
- $UndoResolver
- ./ -- undo actions are automatically generated for binding resolution actions
-
- $Builder /. $BeginFinal
- ./
- $EndBuilder /. /*$builder.getASTStack().print();*/ $EndFinal ./
-
- $resolve /. action.resolver./
- $builder /. action.builder./
-
- $setBinding /. provider.getActiveRule().setData./
- $getBinding /. (IBinding)provider.getActiveRule().getData./
-
- $setScope /. provider.getActiveRule().setData./
- $getScope /. (IC99Scope)provider.getActiveRule().getData./
-
-$End
-
-
-$Headers
-/.
- private C99ParserAction action;
-
- private List commentTokens = new ArrayList();
- private IKeywordMap keywordMap = new $keyword_map_class();
-
- public $action_type() { // constructor
- this(new $lexer_class());
- }
-
- private void initActions() {
- // binding resolution actions need access to IASTName nodes, temporary
- action = new C99ParserAction();
- action.resolver = new $resolve_action_class(this);
- action.builder = new $build_action_class(this);
- action.builder.setTokenMap(C99Parsersym.orderedTerminalSymbols);
- parserAction = action;
- }
-
- public void addToken(IToken token) {
- int newKind = mapKind(token.getKind());
- if(keywordMap != null && newKind == $prs_type.TK_identifier) {
- Integer keywordKind = keywordMap.getKeywordKind(token.toString());
- if(keywordKind != null) {
- newKind = keywordKind.intValue();
- }
- }
- token.setKind(newKind);
- super.addToken(token);
- }
-
- public void addCommentToken(IToken token) {
- commentTokens.add(token);
- }
-
- public List getCommentTokens() {
- return commentTokens;
- }
-
- public IParseResult parse() {
- // this has to be done, or... kaboom!
- setStreamLength(getSize());
- initActions();
- commentTokens = new ArrayList();
-
- final int errorRepairCount = -1; // -1 means full error handling
- parser(null, errorRepairCount);
- super.resetTokenStream();
-
- IASTTranslationUnit tu = action.builder.getAST();
- boolean encounteredError = action.builder.encounteredError();
- IASTCompletionNode compNode = action.builder.getASTCompletionNode();
-
- boolean assertionsEnabled = false;
- assert assertionsEnabled = true;
- if(assertionsEnabled) {
- DebugUtil.assertBindings(tu);
- }
-
- action = null;
- parserAction = null;
- return new C99ParseResult(tu, compNode, encounteredError);
- }
-
- // implements IParserActionTokenProvider.getEOFToken()
- public IToken getEOFToken() {
- List tokens = getTokens();
- IToken eof = (IToken) tokens.get(tokens.size() - 1);
- return eof;
- }
-
- public int getKind(int i) {
- int kind = super.getKind(i);
- if(kind == C99Parsersym.TK_identifier && action.resolver.isTypedef(getTokenText(i))) {
- kind = C99Parsersym.TK_TypedefName;
- }
- return kind;
- }
-
-./
-$End
-
-
-$Start -- the grammar start symbol
- translation_unit
-$End
-
-
-
-$Rules
-
--------------------------------------------------------------------------------------------
--- AST and Symbol Table Scoping
--------------------------------------------------------------------------------------------
-
-
-<openscope-ast>
- ::= $empty
- /.$Action $Builder $builder.openASTScope(); $EndBuilder $EndAction./
-
-<openscope-symbol>
- ::= $empty
- /.$Action $Resolve $resolve.openSymbolScope(); $EndResolve $EndAction./
-
-<openscope-declaration>
- ::= $empty
- /.$Action $Resolve $resolve.openDeclarationScope(); $EndResolve $EndAction./
-
-<openscope-name> ::= $empty
-
--------------------------------------------------------------------------------------------
--- Content assist
--------------------------------------------------------------------------------------------
-
-']' ::=? 'RightBracket'
--- | 'EndOfCompletion'
-
-')' ::=? 'RightParen'
--- | 'EndOfCompletion'
-
-'}' ::=? 'RightBrace'
--- | 'EndOfCompletion'
-
-';' ::=? 'SemiColon'
--- | 'EndOfCompletion'
-
-
-
--------------------------------------------------------------------------------------------
--- Expressions
--------------------------------------------------------------------------------------------
-
-
-constant
- ::= 'integer'
- /.
- $Action
- $Resolve $resolve.consumeExpressionConstant(IASTLiteralExpression.lk_integer_constant); $EndResolve
- $Builder $builder.consumeExpressionConstant(IASTLiteralExpression.lk_integer_constant); $EndBuilder
- $EndAction
- ./
- | 'floating'
- /.
- $Action
- $Resolve $resolve.consumeExpressionConstant(IASTLiteralExpression.lk_float_constant); $EndResolve
- $Builder $builder.consumeExpressionConstant(IASTLiteralExpression.lk_float_constant); $EndBuilder
- $EndAction
- ./
- | 'charconst'
- /.
- $Action
- $Resolve $resolve.consumeExpressionConstant(IASTLiteralExpression.lk_char_constant); $EndResolve
- $Builder $builder.consumeExpressionConstant(IASTLiteralExpression.lk_char_constant); $EndBuilder
- $EndAction
- ./
- | 'stringlit'
- /.
- $Action
- $Resolve $resolve.consumeExpressionConstant(IASTLiteralExpression.lk_string_literal); $EndResolve
- $Builder $builder.consumeExpressionConstant(IASTLiteralExpression.lk_string_literal); $EndBuilder
- $EndAction
- ./
-
-
-primary_expression
- ::= constant
- | primary_expression_id
- /.
- $Action
- $Resolve $setBinding($resolve.consumeExpressionID()); $EndResolve
- $Builder $builder.consumeExpressionID($getBinding()); $EndBuilder
- $EndAction
- ./
- | '(' expression ')'
- /.
- $Action
- $Builder $builder.consumeExpressionBracketed(); $EndBuilder
- $EndAction
- ./
-
-
-primary_expression_id -- Typedefname not allowed as a variable name.
- ::= 'identifier'
- | 'Completion'
-
-
-<openscope-type>
- ::= $empty
- /. $Action $Resolve $resolve.openTypeScope(); $EndResolve $EndAction ./
-
-
-postfix_expression
- ::= primary_expression
- | postfix_expression '[' expression ']'
- /.
- $Action
- $Resolve $resolve.consumeExpressionArraySubscript(); $EndResolve
- $Builder $builder.consumeExpressionArraySubscript(); $EndBuilder
- $EndAction
- ./
- | postfix_expression '(' ')'
- /.
- $Action
- $Resolve $resolve.consumeExpressionFunctionCall(false); $EndResolve
- $Builder $builder.consumeExpressionFunctionCall(false); $EndBuilder
- $EndAction
- ./
- | postfix_expression '(' <openscope-type> <openscope-ast> argument_expression_list ')'
- /.
- $Action
- $Resolve $resolve.consumeExpressionFunctionCall(true); $EndResolve
- $Builder $builder.consumeExpressionFunctionCall(true); $EndBuilder
- $EndAction
- ./
- | postfix_expression '.' member_name
- /.
- $Action
- $Resolve $setBinding($resolve.consumeExpressionFieldReference(false)); $EndResolve
- $Builder $builder.consumeExpressionFieldReference($getBinding(), false); $EndBuilder
- $EndAction
- ./
- | postfix_expression '->' member_name
- /.
- $Action
- $Resolve $setBinding($resolve.consumeExpressionFieldReference(true)); $EndResolve
- $Builder $builder.consumeExpressionFieldReference($getBinding(), true); $EndBuilder
- $EndAction
- ./
- | postfix_expression '++'
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_postFixIncr); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_postFixIncr); $EndBuilder
- $EndAction
- ./
- | postfix_expression '--'
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_postFixDecr); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_postFixDecr); $EndBuilder
- $EndAction
- ./
- | '(' type_name ')' '{' <openscope-type> <openscope-ast> initializer_list comma_opt '}'
- /.
- $Action
- $Resolve $resolve.consumeExpressionTypeIdInitializer(); $EndResolve
- $Builder $builder.consumeExpressionTypeIdInitializer(); $EndBuilder
- $EndAction
- ./
-
-
-comma_opt
- ::= ',' | $empty
-
-
-member_name
- ::= 'identifier'
- | 'TypedefName'
- | 'Completion'
-
-
-argument_expression_list
- ::= assignment_expression
- | argument_expression_list ',' assignment_expression
-
-
-unary_expression
- ::= postfix_expression
- | '++' unary_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_prefixIncr); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_prefixIncr); $EndBuilder
- $EndAction
- ./
- | '--' unary_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_prefixDecr); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_prefixDecr); $EndBuilder
- $EndAction
- ./
- | '&' cast_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_amper); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_amper); $EndBuilder
- $EndAction
- ./
- | '*' cast_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_star); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_star); $EndBuilder
- $EndAction
- ./
- | '+' cast_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_plus); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_plus); $EndBuilder
- $EndAction
- ./
- | '-' cast_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_minus); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_minus); $EndBuilder
- $EndAction
- ./
- | '~' cast_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_tilde); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_tilde); $EndBuilder
- $EndAction
- ./
- | '!' cast_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_not); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_not); $EndBuilder
- $EndAction
- ./
- | 'sizeof' unary_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnaryOperator(IASTUnaryExpression.op_sizeof); $EndResolve
- $Builder $builder.consumeExpressionUnaryOperator(IASTUnaryExpression.op_sizeof); $EndBuilder
- $EndAction
- ./
- | 'sizeof' '(' type_name ')'
- /.
- $Action
- $Resolve $resolve.consumeExpressionUnarySizeofTypeName(); $EndResolve
- $Builder $builder.consumeExpressionUnarySizeofTypeName(); $EndBuilder
- $EndAction
- ./
-
-
-cast_expression
- ::= unary_expression
- | '(' type_name ')' cast_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionCast(); $EndResolve
- $Builder $builder.consumeExpressionCast(); $EndBuilder
- $EndAction
- ./
-
-
-multiplicative_expression
- ::= cast_expression
- | multiplicative_expression '*' cast_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_multiply); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_multiply); $EndBuilder
- $EndAction
- ./
- | multiplicative_expression '/' cast_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_divide); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_divide); $EndBuilder
- $EndAction
- ./
- | multiplicative_expression '%' cast_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_modulo); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_modulo); $EndBuilder
- $EndAction
- ./
-
-
-additive_expression
- ::= multiplicative_expression
- | additive_expression '+' multiplicative_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_plus); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_plus); $EndBuilder
- $EndAction
- ./
- | additive_expression '-' multiplicative_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_minus); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_minus); $EndBuilder
- $EndAction
- ./
-
-
-shift_expression
- ::= additive_expression
- | shift_expression '<<' additive_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftLeft); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftLeft); $EndBuilder
- $EndAction
- ./
- | shift_expression '>>' additive_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftRight); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftRight); $EndBuilder
- $EndAction
- ./
-
-
-relational_expression
- ::= shift_expression
- | relational_expression '<' shift_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_lessThan); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_lessThan); $EndBuilder
- $EndAction
- ./
- | relational_expression '>' shift_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_greaterThan); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_greaterThan); $EndBuilder
- $EndAction
- ./
- | relational_expression '<=' shift_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_lessEqual); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_lessEqual); $EndBuilder
- $EndAction
- ./
- | relational_expression '>=' shift_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_greaterEqual); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_greaterEqual); $EndBuilder
- $EndAction
- ./
-
-
-equality_expression
- ::= relational_expression
- | equality_expression '==' relational_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_equals); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_equals); $EndBuilder
- $EndAction
- ./
- | equality_expression '!=' relational_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_notequals); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_notequals); $EndBuilder
- $EndAction
- ./
-
-
-AND_expression
- ::= equality_expression
- | AND_expression '&' equality_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryAnd); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryAnd); $EndBuilder
- $EndAction
- ./
-
-
-exclusive_OR_expression
- ::= AND_expression
- | exclusive_OR_expression '^' AND_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryXor); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryXor); $EndBuilder
- $EndAction
- ./
-
-
-inclusive_OR_expression
- ::= exclusive_OR_expression
- | inclusive_OR_expression '|' exclusive_OR_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryOr); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryOr); $EndBuilder
- $EndAction
- ./
-
-
-logical_AND_expression
- ::= inclusive_OR_expression
- | logical_AND_expression '&&' inclusive_OR_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_logicalAnd); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_logicalAnd); $EndBuilder
- $EndAction
- ./
-
-
-logical_OR_expression
- ::= logical_AND_expression
- | logical_OR_expression '||' logical_AND_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_logicalOr); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_logicalOr); $EndBuilder
- $EndAction
- ./
-
-
-conditional_expression
- ::= logical_OR_expression
- | logical_OR_expression '?' expression ':' conditional_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionConditional(); $EndResolve
- $Builder $builder.consumeExpressionConditional(); $EndBuilder
- $EndAction
- ./
-
-
-assignment_expression
- ::= conditional_expression
- | unary_expression '=' assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_assign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_assign); $EndBuilder
- $EndAction
- ./
- | unary_expression '*=' assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_multiplyAssign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_multiplyAssign); $EndBuilder
- $EndAction
- ./
- | unary_expression '/=' assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_divideAssign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_divideAssign); $EndBuilder
- $EndAction
- ./
- | unary_expression '%=' assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_moduloAssign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_moduloAssign); $EndBuilder
- $EndAction
- ./
- | unary_expression '+=' assignment_expression
- /.$Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_plusAssign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_plusAssign); $EndBuilder
- $EndAction
- ./
- | unary_expression '-=' assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_minusAssign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_minusAssign); $EndBuilder
- $EndAction
- ./
- | unary_expression '<<=' assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftLeftAssign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftLeftAssign); $EndBuilder
- $EndAction
- ./
- | unary_expression '>>=' assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftRightAssign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_shiftRightAssign); $EndBuilder
- $EndAction
- ./
- | unary_expression '&=' assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryAndAssign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryAndAssign); $EndBuilder
- $EndAction
- ./
- | unary_expression '^=' assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryXorAssign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryXorAssign); $EndBuilder
- $EndAction
- ./
- | unary_expression '|=' assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryOrAssign); $EndResolve
- $Builder $builder.consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryOrAssign); $EndBuilder
- $EndAction
- ./
-
-
--- special rule to avoid conflict between problem statements and problem expressions
-expression_in_statement
- ::= <openscope-ast> expression_list
- /.$Action $Builder $builder.consumeExpression(); $EndBuilder $EndAction./
-
-
-expression
- ::= <openscope-ast> expression_list
- /.$Action $Builder $builder.consumeExpression(); $EndBuilder $EndAction./
-
-
-expression_list
- ::= assignment_expression
- | expression_list ',' assignment_expression
-
-
-constant_expression
- ::= conditional_expression
-
-
--------------------------------------------------------------------------------------------
--- Statements
--------------------------------------------------------------------------------------------
-
-
-
-statement
- ::= labeled_statement
- | compound_statement
- | expression_statement
- | selection_statement
- | iteration_statement
- | jump_statement
- | ERROR_TOKEN
- /.$Action $Builder $builder.consumeStatementProblem(); $EndBuilder $EndAction./
-
-
-labeled_statement
- ::= identifier_or_typedefname ':' statement
- /.
- $Action
- $Resolve $setBinding($resolve.consumeStatementLabeled()); $EndResolve
- $Builder $builder.consumeStatementLabeled($getBinding()); $EndBuilder
- $EndAction
- ./
- | 'case' constant_expression ':'
- /.$Action $Builder $builder.consumeStatementCase(); $EndBuilder $EndAction./
- | 'default' ':'
- /.$Action $Builder $builder.consumeStatementDefault(); $EndBuilder $EndAction./
-
-
-compound_statement
- ::= <openscope-symbol> '{' '}'
- /.
- $Action
- $Resolve $setScope($resolve.closeSymbolScope()); $EndResolve
- $Builder $builder.consumeStatementCompoundStatementEmpty($getScope()); $EndBuilder
-
- $EndAction
- ./
- | <openscope-symbol> '{' <openscope-ast> block_item_list '}'
- /.
- $Action
- $Resolve $setScope($resolve.closeSymbolScope()); $EndResolve
- $Builder $builder.consumeStatementCompoundStatement($getScope()); $EndBuilder
- $EndAction
- ./
-
-
-block_item_list
- ::= block_item
- | block_item_list block_item
-
-
-block_item
- ::= statement
- | declaration
- /.$Action $Builder $builder.consumeStatementDeclaration(); $EndBuilder $EndAction./
-
-
-expression_statement
- ::= ';'
- /.$Action $Builder $builder.consumeStatementNull(); $EndBuilder $EndAction./
- | expression_in_statement ';'
- /.$Action $Builder $builder.consumeStatementExpression(); $EndBuilder $EndAction./
-
-
-selection_statement
- ::= 'if' '(' expression ')' statement
- /.$Action $Builder $builder.consumeStatementIfThen(); $EndBuilder $EndAction./
- | 'if' '(' expression ')' statement 'else' statement
- /.$Action $Builder $builder.consumeStatementIfThenElse(); $EndBuilder $EndAction./
- | 'switch' '(' expression ')' statement
- /.$Action $Builder $builder.consumeStatementSwitch(); $EndBuilder $EndAction./
-
-
-expression_opt
- ::= expression
- | $empty
- /.$Action $Builder $builder.consumeExpressionOptional(); $EndBuilder $EndAction./
-
-
-iteration_statement
- ::= 'do' statement 'while' '(' expression ')' ';'
- /.$Action $Builder $builder.consumeStatementDoLoop(); $EndBuilder $EndAction./
- | 'while' '(' expression ')' statement
- /.$Action $Builder $builder.consumeStatementWhileLoop(); $EndBuilder $EndAction./
- | <openscope-symbol> 'for' '(' expression_opt ';' expression_opt ';' expression_opt ')' statement
- /.
- $Action
- $Resolve $resolve.closeSymbolScope(); $EndResolve
- $Builder $builder.consumeStatementForLoop(); $EndBuilder
- $EndAction
- ./
- | <openscope-symbol> 'for' '(' declaration expression_opt ';' expression_opt ')' statement
- /.
- $Action
- $Resolve $resolve.closeSymbolScope(); $EndResolve
- $Builder $builder.consumeStatementForLoop(); $EndBuilder
- $EndAction
- ./
-
-
-jump_statement
- ::= 'goto' identifier_or_typedefname ';'
- /.
- $Action
- $Resolve $setBinding($resolve.consumeStatementGoto()); $EndResolve
- $Builder $builder.consumeStatementGoto($getBinding()); $EndBuilder
- $EndAction
- ./
- | 'continue' ';'
- /.$Action $Builder $builder.consumeStatementContinue(); $EndBuilder $EndAction./
- | 'break' ';'
- /.$Action $Builder $builder.consumeStatementBreak(); $EndBuilder $EndAction./
- | 'return' ';'
- /.$Action $Builder $builder.consumeStatementReturn(false); $EndBuilder $EndAction./
- | 'return' expression ';'
- /.$Action $Builder $builder.consumeStatementReturn(true); $EndBuilder $EndAction./
-
-
-
--------------------------------------------------------------------------------------------
--- Declarations
--------------------------------------------------------------------------------------------
-
-
-
-declaration
- ::= declaration_specifiers ';'
- /.
- $Action
- $Resolve $resolve.closeDeclarationScope(); $EndResolve
- $Builder $builder.consumeDeclaration(false); $EndBuilder
- $EndAction
- ./
- | declaration_specifiers <openscope-ast> init_declarator_list ';'
- /.
- $Action
- $Resolve $resolve.closeDeclarationScope(); $EndResolve
- $Builder $builder.consumeDeclaration(true); $EndBuilder
- $EndAction
- ./
-
-
-declaration_specifiers
- ::= <openscope-declaration> <openscope-ast> simple_declaration_specifiers
- /.$Action $Builder $builder.consumeDeclarationSpecifiersSimple(); $EndBuilder $EndAction./
- | <openscope-declaration> <openscope-ast> struct_or_union_declaration_specifiers
- /.$Action $Builder $builder.consumeDeclarationSpecifiersStructUnionEnum(); $EndBuilder $EndAction./
- | <openscope-declaration> <openscope-ast> elaborated_declaration_specifiers
- /.$Action $Builder $builder.consumeDeclarationSpecifiersStructUnionEnum(); $EndBuilder $EndAction./
- | <openscope-declaration> <openscope-ast> enum_declaration_specifiers
- /.$Action $Builder $builder.consumeDeclarationSpecifiersStructUnionEnum(); $EndBuilder $EndAction./
- | <openscope-declaration> <openscope-ast> typdef_name_declaration_specifiers
- /.
- $Action
- $Resolve $setBinding($resolve.consumeDeclarationSpecifiersTypedefName()); $EndResolve
- $Builder $builder.consumeDeclarationSpecifiersTypedefName($getBinding()); $EndBuilder
- $EndAction
- ./
-
-
-no_type_declaration_specifier
- ::= storage_class_specifier
- | type_qualifier
- | function_specifier
-
-
-no_type_declaration_specifiers
- ::= no_type_declaration_specifier
- | no_type_declaration_specifiers no_type_declaration_specifier
-
-
-simple_declaration_specifiers
- ::= type_specifier
- | no_type_declaration_specifiers type_specifier
- | simple_declaration_specifiers type_specifier
- | simple_declaration_specifiers no_type_declaration_specifier
-
-
-struct_or_union_declaration_specifiers
- ::= struct_or_union_specifier
- | no_type_declaration_specifiers struct_or_union_specifier
- | struct_or_union_declaration_specifiers no_type_declaration_specifier
-
-
-elaborated_declaration_specifiers
- ::= elaborated_specifier
- | no_type_declaration_specifiers elaborated_specifier
- | elaborated_declaration_specifiers no_type_declaration_specifier
-
-
-enum_declaration_specifiers
- ::= enum_specifier
- | no_type_declaration_specifiers enum_specifier
- | enum_declaration_specifiers no_type_declaration_specifier
-
-
-typdef_name_declaration_specifiers
- ::= typedef_name
- | no_type_declaration_specifiers typedef_name
- | typdef_name_declaration_specifiers no_type_declaration_specifier
-
-
-init_declarator_list
- ::= init_declarator
- | init_declarator_list ',' init_declarator
-
-
-init_declarator
- ::= complete_declarator
- /.
- $Action
- $Resolve $resolve.consumeInitDeclarator(); $EndResolve
- $EndAction
- ./
- | complete_declarator '=' initializer
- /.
- $Action
- $Resolve $resolve.consumeInitDeclarator(); $EndResolve
- $Builder $builder.consumeDeclaratorWithInitializer(); $EndBuilder
- $EndAction
- ./
-
-
-complete_declarator
- ::= declarator
- /.
- $Action
- $Resolve $setBinding($resolve.consumeDeclaratorComplete()); $EndResolve
- $Builder $builder.consumeDeclaratorComplete($getBinding()); $EndBuilder
- $EndAction
- ./
-
-
-storage_class_specifier
- ::= storage_class_specifier_token
- /.
- $Action
- $Resolve $resolve.consumeDeclSpecToken(); $EndResolve
- $Builder $builder.consumeDeclSpecToken(); $EndBuilder
- $EndAction
- ./
-
-
-storage_class_specifier_token
- ::= 'typedef'
- | 'extern'
- | 'static'
- | 'auto'
- | 'register'
-
-
-type_specifier
- ::= type_specifier_token
- /.
- $Action
- $Resolve $resolve.consumeDeclSpecToken(); $EndResolve
- $Builder $builder.consumeDeclSpecToken(); $EndBuilder
- $EndAction
- ./
-
-type_specifier_token
- ::= 'void'
- | 'char'
- | 'short'
- | 'int'
- | 'long'
- | 'float'
- | 'double'
- | 'signed'
- | 'unsigned'
- | '_Bool'
- | '_Complex'
- | '_Imaginary'
-
-
-typedef_name
- ::= 'TypedefName'
- /.
- $Action
- $Resolve $resolve.consumeDeclSpecToken(); $EndResolve
- $Builder $builder.consumeDeclSpecToken(); $EndBuilder
- $EndAction
- ./
-
-
-identifier_or_typedefname
- ::= 'identifier'
- | 'TypedefName'
-
-
-struct_or_union_specifier
- ::= 'struct' '{' <openscope-name> <openscope-ast> struct_declaration_list_opt '}'
- /.
- $Action
- $Resolve $setBinding($resolve.consumeTypeSpecifierComposite(false, IASTCompositeTypeSpecifier.k_struct)); $EndResolve
- $Builder $builder.consumeTypeSpecifierComposite(false, IASTCompositeTypeSpecifier.k_struct, $getBinding()); $EndBuilder
- $EndAction
- ./
- | 'union' '{' <openscope-name> <openscope-ast> struct_declaration_list_opt '}'
- /.
- $Action
- $Resolve $setBinding($resolve.consumeTypeSpecifierComposite(false, IASTCompositeTypeSpecifier.k_union)); $EndResolve
- $Builder $builder.consumeTypeSpecifierComposite(false, IASTCompositeTypeSpecifier.k_union, $getBinding()); $EndBuilder
- $EndAction
- ./
- | 'struct' identifier_or_typedefname '{' <openscope-name> <openscope-ast> struct_declaration_list_opt '}'
- /.
- $Action
- $Resolve $setBinding($resolve.consumeTypeSpecifierComposite(true, IASTCompositeTypeSpecifier.k_struct)); $EndResolve
- $Builder $builder.consumeTypeSpecifierComposite(true, IASTCompositeTypeSpecifier.k_struct, $getBinding()); $EndBuilder
- $EndAction
- ./
- | 'union' identifier_or_typedefname '{' <openscope-name> <openscope-ast> struct_declaration_list_opt '}'
- /.
- $Action
- $Resolve $setBinding($resolve.consumeTypeSpecifierComposite(true, IASTCompositeTypeSpecifier.k_union)); $EndResolve
- $Builder $builder.consumeTypeSpecifierComposite(true, IASTCompositeTypeSpecifier.k_union, $getBinding()); $EndBuilder
- $EndAction
- ./
-
-
-elaborated_specifier
- ::= 'struct' identifier_or_typedefname
- /.
- $Action
- $Resolve $setBinding($resolve.consumeTypeSpecifierElaborated(IASTCompositeTypeSpecifier.k_struct)); $EndResolve
- $Builder $builder.consumeTypeSpecifierElaborated(IASTCompositeTypeSpecifier.k_struct, $getBinding()); $EndBuilder
- $EndAction
- ./
- | 'union' identifier_or_typedefname
- /.
- $Action
- $Resolve $setBinding($resolve.consumeTypeSpecifierElaborated(IASTCompositeTypeSpecifier.k_union)); $EndResolve
- $Builder $builder.consumeTypeSpecifierElaborated(IASTCompositeTypeSpecifier.k_union, $getBinding()); $EndBuilder
- $EndAction
- ./
- | 'enum' identifier_or_typedefname
- /.
- $Action
- $Resolve $setBinding($resolve.consumeTypeSpecifierElaborated(IASTElaboratedTypeSpecifier.k_enum)); $EndResolve
- $Builder $builder.consumeTypeSpecifierElaborated(IASTElaboratedTypeSpecifier.k_enum, $getBinding()); $EndBuilder
- $EndAction
- ./
-
-
-struct_declaration_list_opt
- ::= struct_declaration_list
- | $empty
-
-struct_declaration_list
- ::= struct_declaration
- | struct_declaration_list struct_declaration
-
-
-struct_declaration
- ::= specifier_qualifier_list <openscope-ast> struct_declarator_list ';' -- regular declarators plus bit fields
- /.
- $Action
- $Resolve $resolve.closeDeclarationScope(); $EndResolve
- $Builder $builder.consumeStructDeclaration(true); $EndBuilder
- $EndAction
- ./
- | specifier_qualifier_list ';'
- /.
- $Action
- $Resolve $resolve.closeDeclarationScope(); $EndResolve
- $Builder $builder.consumeStructDeclaration(false); $EndBuilder
- $EndAction
- ./
-
-
--- just reuse declaration_specifiers, makes grammar a bit more lenient but thats OK
-specifier_qualifier_list
- ::= declaration_specifiers
-
-
-struct_declarator_list
- ::= complete_struct_declarator
- | struct_declarator_list ',' complete_struct_declarator
-
-
-complete_struct_declarator
- ::= struct_declarator
- /.
- $Action
- $Resolve $setBinding($resolve.consumeDeclaratorCompleteField()); $EndResolve
- $Builder $builder.consumeDeclaratorCompleteField($getBinding()); $EndBuilder
- $EndAction
- ./
-
-
-struct_declarator
- ::= declarator
- | ':' constant_expression
- /.$Action $Builder $builder.consumeStructBitField(false); $EndBuilder $EndAction./
- | declarator ':' constant_expression
- /.$Action $Builder $builder.consumeStructBitField(true); $EndBuilder $EndAction./
-
-
-enum_specifier
- ::= 'enum' '{' <openscope-name> <openscope-ast> enumerator_list_opt comma_opt '}'
- /.
- $Action
- $Resolve $setBinding($resolve.consumeTypeSpecifierEnumeration(false)); $EndResolve
- $Builder $builder.consumeTypeSpecifierEnumeration(false, $getBinding()); $EndBuilder
- $EndAction
- ./
- | 'enum' identifier_or_typedefname '{' <openscope-name> <openscope-ast> enumerator_list_opt comma_opt '}'
- /.
- $Action
- $Resolve $setBinding($resolve.consumeTypeSpecifierEnumeration(true)); $EndResolve
- $Builder $builder.consumeTypeSpecifierEnumeration(true, $getBinding()); $EndBuilder
- $EndAction
- ./
-
-
-
-enumerator_list_opt
- ::= enumerator_list
- | $empty
-
-
-enumerator_list
- ::= enumerator
- | enumerator_list ',' enumerator
-
-
-enumerator
- ::= identifier_or_typedefname
- /.
- $Action
- $Resolve $setBinding($resolve.consumeEnumerator(false)); $EndResolve
- $Builder $builder.consumeEnumerator(false, $getBinding()); $EndBuilder
- $EndAction
- ./
- | identifier_or_typedefname '=' constant_expression
- /.
- $Action
- $Resolve $setBinding($resolve.consumeEnumerator(false)); $EndResolve
- $Builder $builder.consumeEnumerator(false, $getBinding()); $EndBuilder
- $EndAction
- ./
-
-
-type_qualifier
- ::= type_qualifier_token
- /.
- $Action
- $Resolve $resolve.consumeDeclSpecToken(); $EndResolve
- $Builder $builder.consumeDeclSpecToken(); $EndBuilder
- $EndAction
- ./
-
-
-type_qualifier_token
- ::= 'const'
- | 'restrict'
- | 'volatile'
-
-
-function_specifier
- ::= 'inline'
- /.$Action
- $Resolve $resolve.consumeDeclSpecToken(); $EndResolve
- $Builder $builder.consumeDeclSpecToken(); $EndBuilder
- $EndAction
- ./
-
-
-declarator
- ::= direct_declarator
- | <openscope-ast> pointer direct_declarator
- /.
- $Action
- $Resolve $resolve.consumeDeclaratorWithPointer(); $EndResolve
- $Builder $builder.consumeDeclaratorWithPointer(true); $EndBuilder
- $EndAction
- ./
-
-
-direct_declarator
- ::= array_direct_declarator
- | function_prototype_direct_declarator
- | basic_direct_declarator
-
-
-basic_direct_declarator
- ::= 'identifier'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorIdentifier(); $EndResolve
- $Builder $builder.consumeDirectDeclaratorIdentifier(); $EndBuilder
- $EndAction
- ./
- | '(' declarator ')'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorBracketed(); $EndResolve
- $Builder $builder.consumeDirectDeclaratorBracketed(); $EndBuilder
- $EndAction
- ./
-
-
-array_direct_declarator
- ::= basic_direct_declarator array_modifier
- /.
- $Action
- $Resolve /*$resolve.consumeDirectDeclaratorArrayDeclarator();*/ $EndResolve
- $Builder $builder.consumeDirectDeclaratorArrayDeclarator(); $EndBuilder
- $EndAction
- ./
- | array_direct_declarator array_modifier
- /.
- $Action
- $Resolve /*$resolve.consumeDirectDeclaratorArrayDeclarator();*/ $EndResolve
- $Builder $builder.consumeDirectDeclaratorArrayDeclarator(); $EndBuilder
- $EndAction
- ./
-
-
-function_prototype_direct_declarator
- ::= function_direct_declarator
- /.$Action $Resolve $resolve.closeSymbolScope(); $EndResolve $EndAction./
-
-
-function_direct_declarator
- ::= basic_direct_declarator '(' <openscope-name> <openscope-symbol> <openscope-ast> parameter_type_list ')'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorFunctionDeclarator(); $EndResolve
- $Builder $builder.consumeDirectDeclaratorFunctionDeclarator(true); $EndBuilder
- $EndAction
- ./
- | basic_direct_declarator '(' <openscope-name> <openscope-symbol> ')'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorFunctionDeclarator(); $EndResolve
- $Builder $builder.consumeDirectDeclaratorFunctionDeclarator(false); $EndBuilder
- $EndAction
- ./
-
-
-function_declarator
- ::= function_direct_declarator
- | <openscope-ast> pointer function_direct_declarator
- /.
- $Action
- $Resolve $resolve.consumeDeclaratorWithPointer(); $EndResolve
- $Builder $builder.consumeDeclaratorWithPointer(true); $EndBuilder
- $EndAction
- ./
-
-
--- This is a hack because the parser cannot tell the difference between
--- plain identifiers and types. Because of this an identifier_list would
--- always be parsed as a parameter_type_list instead. In a KnR funciton
--- definition we can use the extra list of declarators to disambiguate.
--- This rule should be merged back into direct_declarator if type info is
--- added to the parser.
---knr_direct_declarator
--- ::= basic_direct_declarator '(' <openscope-ast> identifier_list ')'
--- -- /.$ba consumeDirectDeclaratorFunctionDeclaratorKnR(); $ea./
---
---
---knr_function_declarator
--- ::= knr_direct_declarator
--- | <openscope> pointer knr_direct_declarator
--- -- /.$ba consumeDeclaratorWithPointer(true); $ea./
---
---identifier_list
--- ::= 'identifier'
--- -- /.$ba consumeName(); $ea./
--- | identifier_list ',' 'identifier'
--- -- /.$ba consumeName(); $ea./
-
-
-array_modifier
- ::= '[' ']'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorArrayModifier(); $EndResolve
- $Builder $builder.consumeDirectDeclaratorArrayModifier(false); $EndBuilder
- $EndAction
- ./
- | '[' <openscope-ast> array_modifier_type_qualifiers ']'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorModifiedArrayModifier(false, false, true); $EndResolve
- $Builder $builder.consumeDirectDeclaratorModifiedArrayModifier(false, false, true, false); $EndBuilder
- $EndAction
- ./
- | '[' assignment_expression ']'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorArrayModifier(); $EndResolve
- $Builder $builder.consumeDirectDeclaratorArrayModifier(true); $EndBuilder
- $EndAction
- ./
- | '[' <openscope-ast> array_modifier_type_qualifiers assignment_expression ']'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorModifiedArrayModifier(false, false, true); $EndResolve
- $Builder $builder.consumeDirectDeclaratorModifiedArrayModifier(false, false, true, true); $EndBuilder
- $EndAction
- ./
- | '[' 'static' assignment_expression ']'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorModifiedArrayModifier(true, false, false); $EndResolve
- $Builder $builder.consumeDirectDeclaratorModifiedArrayModifier(true, false, false, true); $EndBuilder
- $EndAction
- ./
- | '[' 'static' <openscope-ast> array_modifier_type_qualifiers assignment_expression ']'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorModifiedArrayModifier(true, false, true); $EndResolve
- $Builder $builder.consumeDirectDeclaratorModifiedArrayModifier(true, false, true, true); $EndBuilder
- $EndAction
- ./
- | '[' <openscope-ast> array_modifier_type_qualifiers 'static' assignment_expression ']'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorModifiedArrayModifier(true, false, true); $EndResolve
- $Builder $builder.consumeDirectDeclaratorModifiedArrayModifier(true, false, true, true); $EndBuilder
- $EndAction
- ./
- | '[' '*' ']'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorModifiedArrayModifier(false, true, false); $EndResolve
- $Builder $builder.consumeDirectDeclaratorModifiedArrayModifier(false, true, false, false); $EndBuilder
- $EndAction
- ./
- | '[' <openscope-ast> array_modifier_type_qualifiers '*' ']'
- /.
- $Action
- $Resolve $resolve.consumeDirectDeclaratorModifiedArrayModifier(false, true, true); $EndResolve
- $Builder $builder.consumeDirectDeclaratorModifiedArrayModifier(false, true, true, false); $EndBuilder
- $EndAction
- ./
-
-
-array_modifier_type_qualifiers
- ::= type_qualifier_list
- /.$Action $Resolve $resolve.consumeTypeQualifiers(); $EndResolve $EndAction./
-
-
-<openscope-pointer>
- ::= $empty
- /.$Action $Resolve $resolve.openPointerScope(); $EndResolve $EndAction./
-
-
-pointer
- ::= <openscope-pointer> pointers
-
-
-pointers
- ::= '*'
- /.
- $Action
- $Resolve $resolve.consumePointer(); $EndResolve
- $Builder $builder.consumePointer(); $EndBuilder
- $EndAction
- ./
- | pointers '*'
- /.
- $Action
- $Resolve $resolve.consumePointer(); $EndResolve
- $Builder $builder.consumePointer(); $EndBuilder
- $EndAction
- ./
- | '*' <openscope-ast> pointer_type_qualifiers
- /.
- $Action
- $Resolve $resolve.consumePointerTypeQualifierList(); $EndResolve
- $Builder $builder.consumePointerTypeQualifierList(); $EndBuilder
- $EndAction
- ./
- | pointers '*' <openscope-ast> pointer_type_qualifiers
- /.
- $Action
- $Resolve $resolve.consumePointerTypeQualifierList(); $EndResolve
- $Builder $builder.consumePointerTypeQualifierList(); $EndBuilder
- $EndAction
- ./
-
-
-pointer_type_qualifiers
- ::= type_qualifier_list
- /.$Action $Resolve $resolve.consumeTypeQualifiers(); $EndResolve $EndAction./
-
-
-type_qualifier_list
- ::= type_qualifier
- | type_qualifier_list type_qualifier
-
-
-parameter_type_list
- ::= parameter_list
- | parameter_list ',' '...'
- | '...' -- not spec
-
-
-parameter_list
- ::= parameter_declaration
- | parameter_list ',' parameter_declaration
-
-
-parameter_declaration
- ::= declaration_specifiers complete_parameter_declarator
- /.
- $Action
- $Builder $builder.consumeParameterDeclaration(); $EndBuilder
- $EndAction
- ./
- | declaration_specifiers
- /.
- $Action
- $Resolve $setBinding($resolve.consumeParameterDeclarationWithoutDeclarator()); $EndResolve
- $Builder $builder.consumeParameterDeclarationWithoutDeclarator($getBinding()); $EndBuilder
- $EndAction
- ./
-
-
-complete_parameter_declarator
- ::= declarator
- /.
- $Action
- $Resolve $setBinding($resolve.consumeDeclaratorCompleteParameter()); $EndResolve
- $Builder $builder.consumeDeclaratorCompleteParameter($getBinding()); $EndBuilder
- $EndAction
- ./
- | abstract_declarator
- /.
- $Action
- $Resolve $setBinding($resolve.consumeDeclaratorCompleteParameter()); $EndResolve
- $Builder $builder.consumeDeclaratorCompleteParameter($getBinding()); $EndBuilder
- $EndAction
- ./
-
-
--- only used in expressions, eg) sizeof, casts etc...
-type_name
- ::= specifier_qualifier_list
- /.
- $Action
- $Resolve $resolve.consumeTypeId(); $EndResolve
- $Builder $builder.consumeTypeId(false); $EndBuilder
- $EndAction
- ./
- | specifier_qualifier_list abstract_declarator
- /.
- $Action
- $Resolve $resolve.consumeTypeId(); $EndResolve
- $Builder $builder.consumeTypeId(true); $EndBuilder
- $EndAction
- ./
-
-
-abstract_declarator -- a declarator that does not include an identifier
- ::= direct_abstract_declarator
- | <openscope-ast> pointer
- /.
- $Action
- $Resolve $resolve.consumeDeclaratorWithPointer(); $EndResolve
- $Builder $builder.consumeDeclaratorWithPointer(false); $EndBuilder
- $EndAction
- ./
- | <openscope-ast> pointer direct_abstract_declarator
- /.
- $Action
- $Resolve $resolve.consumeDeclaratorWithPointer(); $EndResolve
- $Builder $builder.consumeDeclaratorWithPointer(true); $EndBuilder
- $EndAction
- ./
-
-
--- rewritten to use the more general array_modifier rule
-direct_abstract_declarator
- ::= '(' abstract_declarator ')'
- /.
- $Action
- $Builder $builder.consumeDirectDeclaratorBracketed(); $EndBuilder
- $EndAction
- ./
- | array_modifier
- /.
- $Action
- $Resolve $resolve.consumeAbstractDeclaratorArrayModifier(); $EndResolve
- $Builder $builder.consumeAbstractDeclaratorArrayModifier(false); $EndBuilder
- $EndAction
- ./
- | direct_abstract_declarator array_modifier
- /.
- $Action
- $Resolve $resolve.consumeAbstractDeclaratorArrayModifier(); $EndResolve
- $Builder $builder.consumeAbstractDeclaratorArrayModifier(true); $EndBuilder
- $EndAction
- ./
- | '(' ')'
- /.
- $Action
- $Resolve $resolve.consumeAbstractDeclaratorFunctionDeclarator(); $EndResolve
- $Builder $builder.consumeAbstractDeclaratorFunctionDeclarator(false, false); $EndBuilder
- $EndAction
- ./
- | direct_abstract_declarator '(' ')'
- /.
- $Action
- $Resolve $resolve.consumeAbstractDeclaratorFunctionDeclarator(); $EndResolve
- $Builder $builder.consumeAbstractDeclaratorFunctionDeclarator(true, false); $EndBuilder
- $EndAction
- ./
- | '(' <openscope-name> <openscope-ast> parameter_type_list ')'
- /.
- $Action
- $Resolve $resolve.consumeAbstractDeclaratorFunctionDeclarator(); $EndResolve
- $Builder $builder.consumeAbstractDeclaratorFunctionDeclarator(false, true); $EndBuilder
- $EndAction
- ./
- | direct_abstract_declarator '(' <openscope-name> <openscope-ast> parameter_type_list ')'
- /.
- $Action
- $Resolve $resolve.consumeAbstractDeclaratorFunctionDeclarator(); $EndResolve
- $Builder $builder.consumeAbstractDeclaratorFunctionDeclarator(true, true); $EndBuilder
- $EndAction
- ./
-
-
-
-initializer
- ::= assignment_expression
- /.
- $Action
- $Resolve $resolve.consumeExpressionInitializer(); $EndResolve
- $Builder $builder.consumeInitializer(); $EndBuilder
- $EndAction
- ./
- | '{' <openscope-type> <openscope-ast> initializer_list comma_opt '}'
- /.
- $Action
- $Resolve $resolve.consumeExpressionTypeIdInitializer(); $EndResolve
- $Builder $builder.consumeInitializerList(); $EndBuilder
- $EndAction
- ./
-
-initializer_list
- ::= positional initializer
- | designated_initializer
- | initializer_list ',' positional initializer
- | initializer_list ',' designated_initializer
-
-positional
- ::= $empty
- /.
- $Action
- $Resolve $resolve.consumeInitializerStartPositional(); $EndResolve
- $EndAction
- ./
-
-designated_initializer
- ::= <openscope-ast> designation '=' initializer
- /.$Action $Builder $builder.consumeInitializerDesignated(); $EndBuilder $EndAction./
-
-
-designation
- ::= designator_list
-
-
-designator_list
- ::= designator_base
- | designator_list designator
-
-
-designator_base
- ::= '[' constant_expression ']'
- /.
- $Action
- $Resolve $resolve.consumeDesignatorBaseArray(); $EndResolve
- $Builder $builder.consumeDesignatorArray(); $EndBuilder
- $EndAction
- ./
- | '.' identifier_or_typedefname
- /.
- $Action
- $Resolve $setBinding($resolve.consumeDesignatorBaseField()); $EndResolve
- $Builder $builder.consumeDesignatorField($getBinding()); $EndBuilder
- $EndAction
- ./
-
-designator
- ::= '[' constant_expression ']'
- /.
- $Action
- $Resolve $resolve.consumeExpressionArraySubscript(); $EndResolve
- $Builder $builder.consumeDesignatorArray(); $EndBuilder
- $EndAction
- ./
- | '.' identifier_or_typedefname
- /.
- $Action
- $Resolve $setBinding($resolve.consumeExpressionFieldReference(false)); $EndResolve
- $Builder $builder.consumeDesignatorField($getBinding()); $EndBuilder
- $EndAction
- ./
-
-
--------------------------------------------------------------------------------------------
--- External Definitions
--------------------------------------------------------------------------------------------
-
-translation_unit
- ::= external_declaration_list
- /.
- $Action
- $Resolve $setScope($resolve.getCurrentScope()); $EndResolve
- $Builder $builder.consumeTranslationUnit($getScope()); $EndBuilder
- $EndAction
- ./
- | $empty
- /.
- $Action
- $Resolve $setScope($resolve.getCurrentScope()); $EndResolve
- $Builder $builder.consumeTranslationUnit($getScope()); $EndBuilder
- $EndAction
- ./
-
-
-external_declaration_list
- ::= external_declaration
- | external_declaration_list external_declaration
-
-
-external_declaration
- ::= function_definition
- | declaration
- | ';'
- /.$Action $Builder $builder.consumeDeclarationEmpty(); $EndBuilder $EndAction./
- | ERROR_TOKEN
- /.$Action $Builder $builder.consumeDeclarationProblem(); $EndBuilder $EndAction./
-
-
-declaration_list
- ::= declaration
- | declaration_list declaration
-
-
--- The extra <openscope-ast> nonterminal before declarator in this rule is only there
--- to avoid a shift/reduce error with the rule for declaration.
--- The symbol table scoped is opened in the rule for function_definition_direct_declarator
-function_definition
- ::= declaration_specifiers <openscope-ast> function_definition_direct_declarator <openscope-name> function_body
- /.
- $Action
- $Resolve $resolve.consumeFunctionDefinition(); $EndResolve
- $Builder $builder.consumeFunctionDefinition(true); $EndBuilder
- $EndAction
- ./
-
- -- this rule is here as a special case (its not C99 spec) just to support implicit int in function definitions
- | <openscope-declaration> <openscope-ast> function_definition_direct_declarator <openscope-name> function_body
- /.
- $Action
- $Resolve $resolve.consumeFunctionDefinition(); $EndResolve
- $Builder $builder.consumeFunctionDefinition(false); $EndBuilder
- $EndAction
- ./
-
-
-
-
--- comment out KnR for now
---| declaration_specifiers <openscope-ast> knr_function_declarator <openscope-ast> declaration_list compound_statement
--- /.$ba $resolve.closeDeclarationScope(); $ea./
---
-
-
-
-
--- the symbol table scope that holds the parameter declarations is not closed
--- until after the body of the function has been parsed
-function_definition_direct_declarator
- ::= function_direct_declarator
- /.
- $Action
- $Resolve $setBinding($resolve.consumeFunctionDefinitionHeader()); $EndResolve
- $Builder $builder.consumeFunctionDefinitionHeader($getBinding()); $EndBuilder
- $EndAction
- ./
-
-
--- same syntax as compound_statement but a symbol table scope isn't opened
-function_body
- ::= '{' '}'
- /.
- $Action
- $Resolve $setScope($resolve.getCurrentScope()); $EndResolve
- $Builder $builder.consumeStatementCompoundStatementEmpty($getScope()); $EndBuilder
- $EndAction
- ./
- | '{' <openscope-ast> block_item_list '}'
- /.
- $Action
- $Resolve $setScope($resolve.getCurrentScope()); $EndResolve
- $Builder $builder.consumeStatementCompoundStatement($getScope()); $EndBuilder
- $EndAction
- ./
-
-$End
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParser.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParser.java
index 2806a3354c..5ddde1317b 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParser.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParser.java
@@ -165,7 +165,8 @@ public class CPPParser extends PrsStream implements RuleAction , IParserActionTo
private CPPParserAction action;
// uncomment to use with backtracking parser
-public CPPParser() {}
+public CPPParser() { // constructor
+}
private void initActions(IASTTranslationUnit tu) {
// binding resolution actions need access to IASTName nodes, temporary
@@ -185,6 +186,13 @@ public void addToken(IToken token) {
}
+public void setTokens(List<IToken> tokens) {
+ resetTokenStream();
+ for(IToken token : tokens) {
+ addToken(token);
+ }
+}
+
public IASTCompletionNode parse(IASTTranslationUnit tu) {
// this has to be done, or... kaboom!
setStreamLength(getSize());

Back to the top