[antlr-interest] Compiling generated C Code from ANTLR

Heiko Folkerts Heiko.Folkerts at david-bs.de
Thu Aug 13 01:44:25 PDT 2009


Hello,
I have trouble compiling the generated C code from ANTLR with Visual Studio 2008. I get the following errors:
1>c:\Projekte\modelisar\trunk\vendorsrc\antlr-3.1.3\runtime\C\include\antlr3lexer.h(130) : error C2059: syntax error : '<L_TYPE_raw>'
1>c:\Projekte\modelisar\trunk\vendorsrc\antlr-3.1.3\runtime\C\include\antlr3lexer.h(130) : error C2238: unexpected token(s) preceding ';'

I try to link against the static libraries - but this is before linking so it shouldn't matter. 

The strange thing is, that I can't find any occurence of L_TYPE_RAW in my code or in the antlr headers.

I tried searching the docs and the web but nothing gave me a hint.

Here is the grammar causing the trouble.

/**
\file TFSS.g
\brief Grammatik der Testfallspezifikationssprache (TFSS) */ grammar TFSS; options
    {
    output = AST; // Dieser Parser erstellt einen abstrakten Syntaxbaum (AST)
    language = C;
    ASTLabelType=pANTLR3_BASE_TREE;
    backtrack = true;
    memoize = true;
    }
tokens
    {
    TFSROOT; // Hauptknoten des gesamten AST
    ACTIONEXPRESSION; // Eine Aktion mit Objekte und Option
    STATECHECK; // eine Zustandsprüfung mit Objekt und Option
    PARAMETERLIST; // Eine durch Klammern eingefasste Parameterliste
    PARAM; // Ein einzelner Parameter
    STEP; // ein einzelner Testschritt
    IFEXPRESSION; // Ein Wenn-Dann-Ausdruck
    LOOPEXPRESSION; // eine Schleife
    WHILEEXPRESSION; // Ein Ausdruck für gleichzeitige Zustandsprüfungen und Aktionen } @header {
    #include "../../TFSSController/TFSSElements.h" // Wir verwenden die Enumeration der TFSSElementsklasse für die Objektklassen zur Unterscheidung der Schlüsselwörter
    #include "../../TFSSController/TFSSController.h"
}
@members
{
    LanguageID m_LanguageID;
}

// Eine TFS besteht aus einer Liste von Schritten (steps). Daraus erstellen wir einen AST mit dem imaginären Token TFSROOT als Wurzel.
tfs: steps -> ^(TFSROOT steps);
// Ein Schritt endet immer mit einem Semikolon.
// Eine Liste von Schritten ist somit durch das terminierende Simikolon getrennt.
// Dabei kann auch nur ein Schritt alleine in der Liste stehen.
steps: step ';'+ -> step+;
// Ein Schritt besteht aus der Anweisung und einem Semikolon am Ende (s.o.) // Innerhalb eines Testschritts kann zunächst die Testphase und anschließend der anweisungsblock stehen.
// Phasetag und Anweisung sind durch einen Doppelpunkt getrennt.
// STEP ist dabei der Hauptknoten für die Teile des Testschritts.
step: phasetag ':' statement -> ^(STEP phasetag statement);

// Die Testphase ist entweder leer oder kann in der Symboltabelle nachgeschlagen werden:
// Wir verwenden hierfür eine sog. validating semantic predicate (Siehe The definitive Antlr Reference Chapter 13f)
phasetag:   
    | p = ALPHASTRING {TFSSController::Instance().lookup(TFSSKeyword(QString((char*)$p.text->chars),m_LanguageID)) == TFSSElements::Phase}?
    ;

statement: actionexpression
    | statecheck
    | ifexpression
    | loopexpression
    | whileexpression;
// Eine Zustandsprüfung (statecheck) beinhaltet ein Zustandsobjekt, eine Zustandsoption und den Zustand. Die Option ist wie der Name sagt optional.
// Rechts vom Gleichheitszeichen steht der Zustand.
statecheck: stateobject stateoption '=' selectedstate -> ^(STATECHECK stateobject stateoption selectedstate)
    | stateobject '=' selectedstate -> ^(STATECHECK stateobject selectedstate); // Eine Aktion beinhaltet ein Aktionsobjekt , eine Aktionsoption und die Aktion selbst.
actionexpression: actionobject actionoption action -> ^(ACTIONEXPRESSION actionobject actionoption action)
    | actionobject action -> ^(ACTIONEXPRESSION actionobject action);

// Ein Wenn-Dann-Ausdruck hat optional einen Sonst-Zweig:
ifexpression: ifkeyword condition thenkeyword actionchain elsekeyword actionchain
    -> ^(IFEXPRESSION condition actionchain actionchain)
    | ifkeyword condition thenkeyword actionchain 
    -> ^(IFEXPRESSION condition actionchain);

loopexpression: loopkeyword condition ':' actionchain -> ^(LOOPEXPRESSION condition actionchain);

whileexpression: whilekeyword whilecondition ':' actionchain -> ^(WHILEEXPRESSION whilecondition actionchain);

// eine Bedingung für gleichzeitige Aktionen und Zustandsprüfungen kann sowohl eine Aktionskette als auch Parameter als auch eine Zustandsprüfungskette sein.
whilecondition: condition| actionchain;

condition: parameters | statecheckchain;

actionchain: actionexpression (andkeyword | orkeyword actionchain)*;
statecheckchain: statecheck (andkeyword | orkeyword statecheckchain); // letztlich sind alles einzelne Wörter die sog. keywords
stateobject: keyword;
stateoption: keyword;
selectedstate: keyword;
actionobject: keyword;
actionoption: keyword;
action: keyword;
// die Schlüsselwörter für die Kontrollstrukturen sind jeweils auch nur Schlüsselwörter, müssen aber im System nachgeschlagen werden:
ifkeyword: k=ALPHASTRING {TFSSController::Instance().lookup(TFSSKeyword(QString((char*)$k.text->chars),m_LanguageID)) == TFSSElements::IfKeyword}?;
loopkeyword: k=ALPHASTRING {TFSSController::Instance().lookup(TFSSKeyword(QString((char*)$k.text->chars),m_LanguageID)) == TFSSElements::LoopKeyword}?;
whilekeyword: k=ALPHASTRING {TFSSController::Instance().lookup(TFSSKeyword(QString((char*)$k.text->chars),m_LanguageID)) == TFSSElements::WhileKeyword}?;
thenkeyword: k=ALPHASTRING {TFSSController::Instance().lookup(TFSSKeyword(QString((char*)$k.text->chars),m_LanguageID)) == TFSSElements::ThenKeyword}?;
elsekeyword: k=ALPHASTRING {TFSSController::Instance().lookup(TFSSKeyword(QString((char*)$k.text->chars),m_LanguageID)) == TFSSElements::ElseKeyword}?;
andkeyword: k=ALPHASTRING {TFSSController::Instance().lookup(TFSSKeyword(QString((char*)$k.text->chars),m_LanguageID)) == TFSSElements::AndKeyword}?;
orkeyword: k=ALPHASTRING {TFSSController::Instance().lookup(TFSSKeyword(QString((char*)$k.text->chars),m_LanguageID)) == TFSSElements::OrKeyword}?;

keyword: ALPHASTRING WS+ -> ^(ALPHASTRING) | 
    '"' text '"' ->^(text);
text: ALPHASTRING (WS+ ALPHASTRING)*;
ALPHASTRING: ('a'..'z' | 'A'..'Z')+;
WS: (' ' | '\t' | '\r' | '\n')+;
parameters: '(' parameterdata ')' -> ^(PARAMETERLIST parameterdata)
    |
    ;
parameterdata: param (',' parameterdata)* -> ^(param parameterdata);

param: paramname paramoperator paramvalue (paramunit)? -> ^(PARAM paramname paramoperator paramvalue paramunit);
paramname: ALPHASTRING;
paramoperator: '=' | '<=' | '>=' '?=';
paramvalue: ALPHASTRING | '0'..'9' | '*';
paramunit: ALPHASTRING; // muss später um slashes erweitert werden z.B. für KM/H.

Thanks in advance

Mit freundlichem Gruß
Heiko Folkerts
Systementwicklung und -design
--
______________________________________________
DAVID GmbH · Wendenring 1 · 38114 Braunschweig
Tel.: +49 531 24379-14
Fax.: +49 531 24379-79
E-Mail: mailto:Heiko.Folkerts at david-bs.de
WWW:   http://www.david-bs.de 
Eintragung: Amtsgericht Braunschweig, HRB 3167
Geschäftsführer: Frank Ptok
______________________________________________

 


More information about the antlr-interest mailing list