Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Page Template Language -- help with the grammar !
Folks:

I'm trying to write a server side page templating thingy.

Here's what I would like to do, syntax wise:

[[....]] are code sections.
Code sections are copied to the resulting document verbatim.
If code sections appear within quoted strings, they are
ignored.

[.....] are expression sections. They are converted
into:

out.println(.....)

everywhere they occur in the source (even within quoted
strings).

\[[ escapes the code section. \[[ prevents a code section
from starting and is copied to the resulting document as "[["

\[ escapes the expression section. \[ does not start a
expression section and is copied to the resulting document
as "["

Everything else is html text and is copied to the resulting
document verbatim.

For example:

================ Source ======================
<foo value="[fillin]">bar</foo>

"
some quoted text [[ code section ignored in string ]]
[expression-filledin-string]
"

[[ ...code ]]

\[[  foo ]]
\[ foo ]

===================== Result ========================
<foo value="out.print(fillin)">bar</foo>

"some quoted text [[ -- totally ignored ]]
out.print(filledin2)
"

...code....

[[
foo
]]

[ foo ]
 ========================================
============

Trying to write a grammar/lexer for this is proving
to a be a bit tricky. This is because:

a) [ and [[ have a common prefix "["
b) \[ and \[[ are both valid escape sequences. However,
if I have:

\[[text]]

I want to ignore the entire line, not treat that as:

--> \[ [text] ]  -->  \[ out.print(text) ]


So far I've come up with:

text 		 ->  html* | exp* | code*
html      	 ->  all chars
exp  		 ->  '['   exptext  ']'
code 		 ->  '[['  codetext ']]'
codetext	 ->   (any char)*
exptext		->    (any char)*

But I want to specify that \[ does not start an exp
and \[[ does not start code. How to do that in the grammar ?

I also want to specify that \] does not end an exp
and \]] does not end code. How to do that in the grammar ?

Best regards,
--j
[How come you want to reinvent php rather than using the one that
already exists? -John]


Report this thread to moderator Post Follow-up to this message
Old Post
java
03-26-05 08:59 AM


Re: Page Template Language -- help with the grammar !
Easy fix is to differentiate between the "[", "[[", "\[", and "\[[" in
the lexical analysis phase so that each is assigned a representative
symbol (and ditto that for their partners).

then you have

...
exp	-> LEFT_BRACKET exptext RIGHT_BRACKET
code	-> DBL_LEFT_BRACKET codetext DBL_RIGHT_BRACKET
...

You could do it with the gramatic syntax, but it would be trickier.
What tools are you using?  Are you hand coding?  Is your parser
recursive decent?  Is this a homework assignment?

> But I want to specify that \[ does not start an exp
> and \[[ does not start code. How to do that in the grammar ?
>
> I also want to specify that \] does not end an exp
> and \]] does not end code. How to do that in the grammar ?

Nathan Moore


Report this thread to moderator Post Follow-up to this message
Old Post
Nathan Moore
03-27-05 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Compilers archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:56 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.