|
OsfV1Rules.grm
|
// FILE. . . . . /home/hak/hlt/src/hlt/osfv1/apps/v1/sources/OsfV0Rules.grm // EDIT BY . . . Hassan Ait-Kaci // ON MACHINE. . Hak-Laptop // STARTED ON. . Sun Sep 08 18:31:23 2013
|
/* ************************************************************************ */ /* **************************** GRAMMAR RULES ***************************** */ /* ************************************************************************ */ %%
| $OsvV1Program$ is the grammar's start symbol. It denotes an OSF V1 program, which consists in a sequence of $Statement$ constructs. |
OsfV1Program : Statements_opt ;
| A Statements_opt is a possibly empty sequence of $Statement$ constructs. |
Statements_opt : // Empty programs are ok. */ | Statements_opt Statement ;
| A Statement is $StatementType$ followed by an end of statement marker. |
Statement : StatementType EndOfStatement ;
| EndOfStatement denotes the end of a statement. Upon the end of statement marker EOS the statement is processed and errors that may have occurred are reported. In interactive mode, it also triggers a prompt for additional statements. In case of syntax error, error recovery skips all input until the next end-of-statement marker EOS. |
EndOfStatement
: {
commitParse();
}
EOS
;
A StatementType is the main language unit, an element of the
sequence of statements that make up an OSF V1 program. It can be one
of the following:
|
StatementType
: // Empty statements are ok. */
| Pragma PragmaArguments_opt
{
processPragma($1.svalue().intern(),$2.args);
}
| SortDeclarationStatement
| OsfExpression
| error
;
SortDeclarationStatement
: IsaDeclarationStatement
{
setLocation();
processIsaDeclaration($1.lhs,$1.rhs);
}
// | SortNameDeclarationStatement
// {
// setLocation();
// processtSortNameDeclaration($1.symbols);
// }
;
IsaDeclarationStatement
: SortSymbols ISA SortSymbols
{
$$.lhs = $1.symbols;
$$.rhs = $3.symbols;
}
;
// SortNameDeclarationStatement
// : DECLARESORTS SortSymbols
// {
// $$.symbols = $2.symbols;
// }
// ;
SortSymbol
: IDENTIFIER
;
SortSymbols
: SortSymbol
{
$$.symbols = new Stack();
$$.symbols.push($1.svalue());
}
| SortSymbol ',' SortSymbols
{
($$.symbols = $3.symbols).push($1.svalue());
}
;
OsfExpression
:
// SortExpression
// {
// processSortExpression($1.expression);
// }
// |
PsiTerm
{
processPsiTerm($1.tag,$1.sort,$1.keys,$1.subterms);
}
;
PsiTerm
: TAG
{
$$.tag = $1.svalue();
$$.sort = new SymbolSortExpression("@",context);
}
| UntaggedPsiTerm
{
$$.sort = $1.sort;
$$.keys = $1.keys;
$$.subterms = $1.subterms;
}
| TAG ':' UntaggedPsiTerm
{
$$.tag = $1.svalue();
$$.sort = $3.sort;
$$.keys = $3.keys;
$$.subterms = $3.subterms;
}
;
UntaggedPsiTerm
: SortExpression Body_opt
{
$$.sort = $1.expression;
$$.keys = $2.keys;
$$.subterms = $2.subterms;
}
;
Body_opt
: /* empty */
| '(' SubTerms ')'
{
$$.keys = $2.keys;
$$.subterms = $2.subterms;
}
;
SubTerms
: SubTerm
{
$$.keys = new Stack();
$$.keys.push($1.key);
$$.subterms = new Stack();
$$.subterms.push($1.psiterm);
}
| SubTerm ',' SubTerms
{
($$.keys = $3.keys).push($1.key);
($$.subterms = $3.subterms).push($1.psiterm);
}
;
SubTerm
: PsiTerm
{
$$.key = null;
$$.psiterm = new RawPsiTerm($1.tag,$1.sort,$1.keys,$1.subterms);
}
| Feature ARROW PsiTerm
{
$$.key = $1.feature;
$$.psiterm = new RawPsiTerm($3.tag,$3.sort,$3.keys,$3.subterms);
}
;
Feature
: INTEGER
{
$$.feature = new Integer((int)$1.nvalue());
}
| IDENTIFIER
{
$$.feature = $1.svalue();
}
;
SortExpression
: Constant
{
$$.expression = new ConstantSortExpression($1.constant);
}
| Sort
{
$$.expression = new SymbolSortExpression($1.svalue(),context);
}
| '{' SortList '}'
{
$$.expression = new DisjunctiveSort($2.sortList,context);
}
| NOT SortExpression
{
$$.expression = new NotSortExpression($2.expression);
}
| SortExpression AND SortExpression
{
$$.expression = new AndSortExpression($1.expression,$3.expression);
}
| SortExpression OR SortExpression
{
$$.expression = new OrSortExpression($1.expression,$3.expression);
}
| SortExpression BUTNOT SortExpression
{
$$.expression = new ButnotSortExpression($1.expression,$3.expression);
}
| '(' SortExpression ')'
{
$$.expression = $2.expression.setParenthesized(true);
}
;
Constant
: INTEGER
{ $$.constant = new IntegerConstant((int)$1.nvalue()); }
| CHAR // should check that there's exactly one character!
{ $$.constant = new CharConstant($1.svalue().charAt(0)); }
| FLOAT
{ $$.constant = new FloatConstant($1.nvalue()); }
| STRING
{ $$.constant = new StringConstant($1.svalue()); }
| BOOLEAN
{ $$.constant = new BooleanConstant($1.svalue() == "true" ? true : false); }
// | 'null'
// { $$.constant = Constant.NULL(); }
;
Sort
: TOP
| BOTTOM
| IDENTIFIER
;
SortList
: Sort
{
$$.sortList = new Stack();
$$.sortList.push($1.svalue());
}
| Sort ';' SortList
{
($$.sortList = $3.sortList).push($1.svalue());
}
;
// /**
// * This non-terminal denotes statements used to define a global
// * name associated to a ψ-term.
// */
// DefinitionStatement
// : DEF '=' PsiTerm
// {
// processDefinition($1.name,$3.psiterm);
// }
// ;
|
This node stands for a pragma statement which allows the user to
query state parameters or up some options using a few built-in
extra-language commands of the form %pragma; where pragma is an identifier.
Pragmas to be supported eventually are:
|
Pragma
: PRAGMA
;
PragmaArguments_opt
: // empty */
| INTEGER
{
Decoded.setEnumSize((int)$1.nvalue());
}
| FileList
{
$$.args = $1.files;
}
| SortExpression
{
$$.args = new ArrayList(1);
$$.args.add($1.expression);
}
| SortExpression SortExpression
{
$$.args = new ArrayList(2);
$$.args.add($1.expression);
$$.args.add($2.expression);
}
;
FileList
: STRING
{
$$.files = new Stack();
$$.files.push($1.svalue());
}
| STRING FileList
{
($$.files = $2.files).push($1.svalue());
}
;
%%
/* ************************************************************************ */
/* ************************* END OF GRAMMAR RULES ************************* */
/* ************************************************************************ */
This file was generated on Sun Sep 15 13:38:06 CEST 2013 from file OsfV1Rules.grm
by the hlt.language.tools.Hilite Java tool written by Hassan Aït-Kaci