Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: Re: Re: original definition vs final language

by thraxil (Prior)
on Oct 25, 2002 at 14:53 UTC ( [id://208018]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: original definition vs final language
in thread original definition vs final language

...ANY language that uses arbitrarily nested parenthesis (as in to any level of nesting)...

the rest of your post is spot on (++) but this part i believe is wrong. arbitrarily nested parenthesis are a canonical example of a construct that can't be matched by a finite acceptor (DFA|NFA) but can easily be matched by a pushdown automata (just push everytime you see an open paren, pop everytime you see a closed paren), and hence are valid in context-free languages. almost every textbook on automata and formal languages i've seen uses that as the transition between the Regular Languages chapter and the Context-Free Languages chapter.

anders pearson

  • Comment on Re: Re: Re: Re: original definition vs final language

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: original definition vs final language
by demerphq (Chancellor) on Oct 25, 2002 at 15:14 UTC
    Hmm. Ok, its quite possible i got that wrong. Ill double check in the dragon when I get home (hopefuly soon.)

    But surely the stack itself is a form of context? I mean without _somehow_ counting how many parens you have gone through how do you determine if all the parens have been properly balanced? And counting would seem to me to be a form of context. Also how does such an approach determine that ([)] is an error without context? (Hmm, is the last a good point, im not real sure.)

    BTW, Im really not offering the above as a definitive statement (just in case anybody missed the ?), just my gut reaction.

    Thanks for the reply, I had a feeling after I had posted it that someone would call me on this one, and that i wouldnt be able to properly respond until I get home. *sigh*

    --- demerphq
    my friends call me, usually because I'm late....

      i think you're misunderstanding the meaning of the word 'context' in the term 'context-free grammar'. 'context' isn't the same as 'memory'. check out this wikipedia entry for a decent discussion of CFGs.

      i've had the idea of writing an article on formal language and automata theory aimed at perl programmers floating around in the back of my mind for a while. maybe i should get around to doing that soon.

      the short version as it relates to the topic at hand is this: a Finite Automata is a state machine with a finite number of states. it essentially has 'memory' equal to the number of states in its definition. a pushdown automata is a state machine that uses a stack to store its state so it can essentially have infinite 'memory'. however, because it can only push and pop the stack, it doesn't have a sense of 'context'; it can only see what's at the top of the stack. beyond pushdown automata there are turing machines which use a tape and can access it at any point, so they are able to have a sense of 'context'. languages are defined by the kind of automata that accept them: regular languages are accepted by finite automata, context-free languages are accepted by pushdown automata, context-sensitive languages are accepted by finite turing machines, and recursively enumerable languages are accepted by infinite turing machines. the mapping of languages to machines and how it all fits together is called the Chomsky Hierarchy.

      that was a gross simplification of the whole thing. hopefully i can make up for it with a full article in the near future.

      anders pearson

      I'm no expert on formal languages, but one thing I do remember from college is that balancing parentheses is something that context-free languages are good at. For example, here's a context-free grammar that matches zero or more left parens followed by the same number of right parens:

      S -> ( S ) | ε

      To be honest, I don't remember exactly what "context-free" means in a formal sense, but I don't think it's the same as "no context" in the way that you're thinking.

      -- Mike

      --
      just,my${.02}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://208018]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-19 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found